gpt4 book ai didi

java - 如何使用 Maven 程序集插件向类路径 MANIFEST 条目添加前缀?

转载 作者:行者123 更新时间:2023-11-30 04:01:19 27 4
gpt4 key购买 nike

我正在使用 Maven 3.x 中的程序集插件来创建一个 tar 球,其中包含项目 jar 及其依赖项。为了方便起见,我将项目 jar 放在根目录中,并将所有依赖项 jar 放在 dir 下,例如

├── hpcmom-cmaes-1.1.9-SNAPSHOT.jar
└── lib
├── akka-actor_2.10-2.2.3.jar
├── akka-agent_2.10-2.2.3.jar
├── akka-kernel_2.10-2.2.3.jar
├── akka-remote_2.10-2.2.3.jar
├── akka-slf4j_2.10-2.2.3.jar
├── akka-zeromq_2.10-2.2.3.jar

生成它的程序集定义为:

<assembly>
<id>cmaes-bin</id>
<baseDirectory>${pom.version}/hpcmom-cmaes</baseDirectory>
<formats>
<format>tar.gz</format>
</formats>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory></directory>
<outputDirectory></outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>COPYING*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>hpcmom-cmaes/target</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>

但是 hpcmom-cmaes-1.1.9-SNAPSHOT.jar 中生成的 MANIFEST.MF 不会生成 ./lib/仅适用于第三方依赖项的前缀,但就像所有 jar 都位于同一文件夹中一样。如何通过程序集插件修改 MANIFEST.MF 以便在那里考虑 lib 前缀。

生成的类路径 MANIFEST.MF 如下所示:

 Class-Path: akka-actor_2.10-2.2.3.jar akka-agent_2.10-2.2.3.jar akka-kernel_2.10-2.2.3.jar akka-remote_2.10-2.2.3.jar akka-slf4j_2.10-2.2.3.jar akka-zeromq_2.10-2.2.3.jar

我想要的是:

 Class-Path: lib/akka-actor_2.10-2.2.3.jar lib/akka-agent_2.10-2.2.3.jar lib/akka-kernel_2.10-2.2.3.jar lib/akka-remote_2.10-2.2.3.jar lib/akka-slf4j_2.10-2.2.3.jar lib/akka-zeromq_2.10-2.2.3.jar

更新:

程序集插件配置在父 pom.xml 中如下所示:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/cmaes-bin.xml</descriptor>
<descriptor>src/main/assembly/cmaes-src.xml</descriptor>
</descriptors>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>

最佳答案

尝试将以下插件添加到您的 pom 中。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath> <-- don't know if this is needed -->
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>

关于java - 如何使用 Maven 程序集插件向类路径 MANIFEST 条目添加前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21930270/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com