Reputation: 6227
I have a web application that I build with Maven into a war. But I want to generate a JAR with the maven project with the correct maven directory structure. I tried this but it throws away the Maven directory structure (src/main/java, etc.). My goal is to distribute this jar to other people so they can unpack and run mvn eclipse:eclipse and start working on their new web project.
Upvotes: 3
Views: 1413
Reputation: 466
Actually the best way to create the distribution package of the entire project is to use the descriptorRef named project included in the Maven Assembly Plugin: https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#project
Below an example of a working plugin declaration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<executions>
<execution>
<id>make-distribution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>project</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
Hope this helps :)
Upvotes: 0
Reputation: 97517
Why not using the existing descriptor of maven-assembly-plugin..
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>src</descriptorRef>
</descriptorRefs>
</configuratio
Upvotes: 2
Reputation: 32697
Use the maven-assembly-plugin. It's pretty straight-forward to do what you want.
Here's your definition for the plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>make-distribution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Here's your src/main/assembly/assembly.xml:
<assembly>
<id>my-project</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}</directory>
<includes>
<include>**/**</include>
</includes>
<excludes>
<exclude>**/**</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
I haven't tested it, but it's roughly the way you should set it up.
Upvotes: 0