1
votes

I want to create a JAR file of my maven application. So to bundle the dependencies I have used the maven-assembly-plugin. But I want that the dependencies should go the lib/ folder and not anywhere else. My current pom.xml plugin tag is

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.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>

Please suggest. Also is it possible to achieve the same with maven jar plugin.

After the above changes in POM The dependencies get generated in the jar which is generated with suffix 'jar-with-dependencies'. But the dependent jars are scattered I want all those dependent jars to be part of one folder lib similart to WEB-INF/lib for war files. How do I achieve this?

1
Please specify what the problem is in more concrete way.Alexey Malev
If you like to have all the dependencies within a folder lib than you need having a assembly descriptor BUT this will not work with a jar cause jar does not support such things.khmarbaise

1 Answers

1
votes

You can achieve this with a custom assembly descriptor (a xml file) like this:

<assembly
   xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

  <id>dist</id>

  <formats>
    <format>dir</format>
  </formats>

  <fileSets>
    <fileSet>
      <directory>target</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>your-application.jar</include>
      </includes>
    </fileSet>
  </fileSets>

  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>
  </dependencySets>

</assembly>

You have to point to the assembly descriptor in your maven assembly plugin configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.4.1</version>
  <configuration>
    <descriptors>
      <descriptor>assemble.xml</descriptor>
    </descriptors>
  </configuration>
  ...
</plugin>

Hope that helps