Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I package a jar with Maven and include some dependencies in WEB-INF/lib?

Tags:

maven-2

maven

How can I package a jar with Maven and include some dependencies in WEB-INF/lib?

I tried with assembly, but cannot be achieved easier?

like image 205
ssedano Avatar asked Sep 21 '11 15:09

ssedano


1 Answers

Try using the jar-with-dependencies feature of the maven-assembly-plugin:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id> 
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This will incorporate all dependencies into your jar. Mark the dependencies that you don't want included in your jar with <scope>provided</scope>, eg:

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache-core</artifactId>
    <version>2.4.4</version>
    <scope>provided</scope>
</dependency>
like image 162
fivetenwill Avatar answered Oct 15 '22 07:10

fivetenwill