Maven jar with classpath in manifest

偶尔善良 提交于 2019-12-12 03:17:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!