41

I'm using MyEclipse to develop a really simple Java Struts project. Everything was working fine until I wanted to use the StringUtils class in org.apache.commons.lang. In MyEclipse I imported the package like

import org.apache.commons.lang.StringUtils;

I added the Jar file for commons-lang-2.4 to my build path. This all works fine and dandy and I get the Intellisense and no errors in Eclipse or anything. Now, when I go to do a mvn clean package, I get an error saying that

The package org.apache.commons.lang does not exist

I checked in my war/Pom.xml file and I do have it declared as a dependency

<dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.0.1</version>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.4</version>
    </dependency>

</dependencies>

From my research I figured that Maven should download the package and install it to my local repository if it doesn't exists. I checked the repository and the jar file was in there. I figured the jar file must be corrupted so I deleted the commons-lang folder to get a fresh download of commons-lang. Now this is where it blows my mind, after I deleted it from the local repository and ran a mvn clean package, it goes out and downloads the commons-lang-2.1.pom and jar (even though the pom.xml has 2.4) BUT still gives a compilation failure saying that the package org.apache.commons.lang does not exist.

I haven't been using Maven for very long so I'm not sure how to go about fixing this. Am I missing something? Do I need to add the dependency in another pom.xml file somewhere else?

Rondel
  • 4,811
  • 11
  • 41
  • 67
  • First, I deleted commons-lang in repository, and it worked. – vanduc1102 Aug 22 '16 at 01:34
  • Not sure if there was file corruption or what, but after confirming dependencies via @TomaszNurkiewicz's method I was able to resolve this issue by deleting the jar from my local m2 repository when I ran the tests. – eebbesen Jan 02 '14 at 16:11

6 Answers6

41

Try running the following commands and examine the output:

$ mvn dependency:tree
$ mvn help:effective-pom

Look for commons-lang, maybe something will draw your attention like excludes or dependency overrides. Also, is:

$ mvn dependency:copy-dependencies

copying commons-lang JAR to your target?

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • 6
    Thanks that helped a bunch! I added a reference for the commons-lang 2.4 to my jar pom.xml and now it works. I closed and reopened command prompt before doing the clean package and then it downloaded the correct versions of the jars and built successfully. Should've posted this question hours ago. Thanks – Rondel Sep 07 '11 at 19:37
  • What command prompt we are talking about here? I am using netbeans on windows 8 – RedBirdISU Sep 08 '15 at 17:25
26

Adding following dependency to pom.xml in dependencies tag helped me:

    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.1</version>
    </dependency>
Kavya Pandian
  • 261
  • 3
  • 2
6

I did "mvn clean install -U" without settings.xml, so it erred. Then I added settings.xml, did "mvn clean install -U", it said "error:org.apache.commons-lang does not exist". I know the code was built successfully on another machine. So it was not my code. After about 2 or 3 hours, I finally realized it was .m2\repository was corrupted by my first run. So just delete "repository" folder complete and run "mvn clean install -U" and succeeded.

Janet
  • 772
  • 9
  • 13
0

Add the following in the pom.xml

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

and make sure that your Java code has this import entry import org.apache.commons.lang3.StringUtils; NOT import org.apache.commons.lang.StringUtils;

Please pay attention to lang3 that makes the difference out here.

Ashu
  • 614
  • 8
  • 17
0

I recently faced the same Issue. I tried all the approaches but what I did at last is downloaded the jar file and extracted. In intelliJ, Files > projectStructure > libraries. Click on the plus symbol and the extracted jar file there. I worked as wonder.

-11

In src/main/java there would be a .auth folder. Open the folder, Go to AuthController.java file and delete the import io.swagger line. Restart.