29
votes

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?

5
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
First, I deleted commons-lang in repository, and it worked.vanduc1102

5 Answers

35
votes

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?

13
votes

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>
4
votes

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.

0
votes

Better go with below to avoid clashes :

import org.springframework.util.StringUtils;
-10
votes

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.