javamavenjardependenciesmaven-package

Maven package doesn't include all the dependecy's JARs


I'm creating a WAR for a Java Web application. The problem is that inside the WAR, in /WEB-INF/lib only a few JARs were included.

Here is my POM.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--
*****THIS IS AN AUTOGENERATED POM; PLEASE DO NOT MODIFY OR COMMIT ANY CHANGES*****
-->
   <parent>
    ...
   </parent>
    ...
      <scm>  
          ...
   </scm>
   <packaging>war</packaging>
   <dependencies>
    <dependency>
       ...
    </dependency>
    ...
   </dependencies>  
   <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
        </plugin>
    </plugins>
   </build>
   <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javancss.fail>false</javancss.fail>
        <checkstyle.fail>false</checkstyle.fail>
        <cobertura.fail>true</cobertura.fail>
        <pmd.fail>true</pmd.fail>
        <findbugs.fail>false</findbugs.fail>
   </properties>    
</project>

As an example, I have like 5 dependencies from different Spring modules but it the package I only see one.

All my dependencies have a "compile" scope.

Why is this happening?

Regards.


Solution

  • Ok, I didn't noticed that the missing dependencies were "included" in other projects I had, and these projects expected those dependencies to be provided.

    That is why those dependencies showed in the effective-pom as "provided".

    I locked the dependencies in my POM to make sure that they had the "compile" scope:

    <dependencyManagement>
        <dependencies>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                    <version>3.0.6.RELEASE</version>
                    <scope>compile</scope>
                </dependency>
                ..
        </dependencies>
     </dependencyManagement>
    

    And now the dependencies are being successfully included in WEB-INFO/lib and it fixed the problem of getting the following error each time I tried to deploy:

    java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext 
    

    I feel dumb...

    Thanks for your help.