问题
I am making an extra jar containing the project jar and all dependencies, as part of my maven build (with maven-assembly-plugin):
In assembly XML file:
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
</dependencySet>
In POM:
<archive>
<manifest>
<mainClass>dk.intelligentsystems.platform.deploy.Deployer</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
The jar contains the correct files, but the dependencies are not being added to the manufest Classpath attribute. How can I make that happen?
回答1:
Instead of maven-assembly-plugin, I use maven-shade-plugin in combination with maven-jar-plugin for the same purpose.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>.settings/**</exclude>
<exclude>*.classpath</exclude>
<exclude>*.project</exclude>
<exclude>*.txt</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
来源:https://stackoverflow.com/questions/27040896/maven-jar-with-classpath-in-manifest