I'd like Maven to package a project alongside its run-time dependencies. I expect it to create a JAR file with the following manifest:
.....
Main-Class : com.acme.MainClass
Class-Path : lib/dependency1.jar lib/dependency2.jar
.....
and create the following directory structure:
target
|-- ....
|-- my-project.jar
|-- lib
|-- dependency1.jar
|-- dependency2.jar
Meaning, I want the main JAR to exclude any dependencies and I want all transitive dependencies to get copied into a "lib" sub-directory. Any ideas?
Add the following plugins in pom.xml. Check the value at mainClass,classpathPrefix,addClasspath tags.
Create some-assembly.xml under src/assembly as below.
Note that useProjectArtifact flag to false, unpack flag to false. If root folder inside zip file is not required,then one can make includeBaseDirectory to false.
This will create name-version-distribution.zip file. Inside zip file, there will be folder name-version. Inside this folder, your executable jar and lib folder containing all dependency jars will be present. Check manifest.MF file of executable jar. It contains both main class and classpath information.
This part is unclear (it's not exactly what you describe just after). My answer covers what you described.
Configure the Maven Jar Plugin to do so (or more precisely, the Maven Archiver):
And this will produce a MANIFEST.MF with the following entries:
This is doable using the Maven Dependency Plugin and the
dependency:copy-dependencies
goal. From the documentation:You could bind it on the
package
phase:You can use the maven jar plugin, take a look on this page: http://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html