Search code examples
javamaven

Maven package error: org.apache.commons-lang does not exist (Java)


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?


Solution

  • 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?