Problem description: As a result of the build process I need following artifacts to be generated and packed into single ZIP archive:
- JAR with all compiled classes and resources
- Manifest file with properly configured main class and generated class path
- all dependencies
This problem could be easily solved with Apache Maven build manager.
We need to use and configure following plugins:
- org.apache.maven.plugins/maven-jar-plugin
- org.apache.maven.plugins/maven-dependency-plugin
- org.apache.maven.plugins/maven-assembly-plugin
Configuration of the maven-jar-plugin:
org.apache.maven.plugins maven-jar-plugin false true true libs/ com.mightypocket.ashoter.Main
This plugin creates a jar file for your application. This jar file contains all compiled classes and resources. One very important part of this file is a manifest. To make it possible to be executed without additional configurations it has to have classpath and mainclass entries. There are several options with class path. In the preceding example all libraries are prefixed with "libs/". It gives us an ability to put all required libraries into separated folder "libs".
Configuration for the maven-dependency-plugin.
org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies ${project.build.directory}/libs
This plugin does all dirty work finding and coying all direct and transitive dependencies of the application. Those libraries will be copied into specified folder, "libs" in our case.
Configuration for the maven-assembly-plugin.
The last but not least plugin - Assembly. It put all parts together and puck them into archive. It needs an assembly descriptor to do its job. In this case the descriptor is very simple one:org.apache.maven.plugins maven-assembly-plugin assembly/bin.xml AndroidScreenCapture_${project.version} ${project.build.directory}/dist ${project.build.directory}/assembly/work
bin zip README* LICENSE* NOTICE* target *.jar target/libs libs *.jar

0 comments:
Post a Comment