Maven project deployment

I have a maven project and I would like to create its distribution with dependencies. I tried maven-assembly-plugin and built a jar of dependencies, but it unpacked all the jars and repacked them all into a large single jar. What I would like is something like my jar file and the lib folder, which has all the dependencies. Then, when I started it, I could run "java -cp lib / * my.package.MainClass".

What is the best way to do this using maven? Or the recommended deployment method?

thanks,

Jeff

+4
source share
2 answers

I used the Maven build just for this in my project.

First enable your plugin in your POM and call the build configuration:

<plugin> <artifactId>maven-assembly-plugin</artifactId> <!--I recommend 2.1 as later versions have a bug that may Duplicate files in your archive --> <version>2.1</version> <!--Executes the packaging along with the mvn package phase --> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>attached</goal> </goals> </execution> </executions> <configuration> <descriptors> <!--Relative path to your descriptor --> <descriptor>src/main/assembly/package.xml </descriptor> </descriptors> </configuration> </plugin> 

Then in your descriptor you can decide how you want your layout to be before you pack it all.

 <assembly> <!-- this will create an extra resource project-1.1.1-package.zip, you can choose jar as well in the format--> <id>package</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <!-- Insert here extra files as configs or, batch files, resources, docs etc--> <fileSets> <fileSet> <directory>src/main/assembly/files</directory> <outputDirectory>/</outputDirectory> <includes> <include>**/conf/*.*</include> <include>**/doc/*.*</include> </includes> </fileSet> <!-- I like to integrate the jre as well... simplifies my deployement --> <fileSet> <directory>target/jre</directory> <outputDirectory>/jre</outputDirectory> </fileSet> </fileSets> <!-- This will scrub your dependencies and add them to your lib folder, I excluded Test stuff as it is not needed, could have declared the resource as a test only phase as well would not have had to exclude it here --> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <excludes> <exclude>junit:junit</exclude> </excludes> </dependencySet> </dependencySets> </assembly> 

This will create a zip file with the layout that you specified in your output configuration directory, pack it all as a zip file (you can select zip, jar, war ...) and deploy it to my repository using the rest.

I skipped bits and pieces to simplify it, but my package expands to include batch files, dlls, config, doc and JRE so that everything is in one zip file ... all that is needed to run this thing is extract and click start.bat!

Perhaps I could also do this in a bank properly formatted using METADATA, and just double-click on the bank itself to start all this, I did not need or did not have time to play with this option, but you can also to try.

Beware of versions above 2.1 of the build plugin, it will create duplicate entries, if your directives allow it to find the same file in different places, this will give you a lib folder with the same banks repeating twice. not very dangerous, since unpacking will lead to their collapse, but it is still annoying if you want to unzip them, if you want to overwrite files. Plus the fact that you do not know who won, if in some way they turned out to be different in content.

Maven is great, but I find it sometimes difficult to upset, plus documentation is sometimes difficult to find and use. However, used properly, it will save you a ton of time.

luck

+7
source

Cm:

http://maven.apache.org/shared/maven-archiver/index.html

You should be able to use the maven-jar plugin to package the archive, specify the main class to execute along with the classpath. He can create a manifest file for you for your project.

http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Prefix

+1
source

All Articles