3

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.

pfernandom
  • 929
  • 10
  • 22

3 Answers3

2

by default it doesn't pack dependent libraries in your package, you need to instruct plugin to do it

See

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
  • But it is including some dependencies and others not. All with the same scope. – pfernandom Apr 23 '14 at 18:18
  • For a jar file sure, but for a war it should put all the maven dependencies in WEB-INF/lib by default, unless you put a `packagingExcludes` tag in your `maven-war-plugin` section. – azurefrog Apr 23 '14 at 18:19
  • can you post `mvn help:effective-pom` – jmj Apr 23 '14 at 18:19
  • Looking at the effective-pom, the dependencies I'm missing are being used as "provided". – pfernandom Apr 23 '14 at 18:24
  • provided is saying that it would be provided at runtime so don't add – jmj Apr 23 '14 at 18:26
  • Maven POM Reference says: `provided - this is much like compile, but indicates you expect the JDK or a container to provide it at runtime. It is only available on the compilation and test classpath, and is not transitive.` – azurefrog Apr 23 '14 at 18:26
1

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.

pfernandom
  • 929
  • 10
  • 22
0

You may also be interested in maven-shade-plugin - it makes a big jar out of all your dependencies.

http://maven.apache.org/plugins/maven-shade-plugin/

MonkeyWidget
  • 956
  • 1
  • 9
  • 19