gpt4 book ai didi

java - 构建 jar-with-dependencies 时的 ManifestEntries

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:32:09 25 4
gpt4 key购买 nike

我正在尝试将我的构建服务器信息设置到 META-INF/MANIFEST.MF 中。在将 maven-jar-plugin 与 manifestEntries 一起使用时效果很好。问题是,当我将带有 maven-assembly-plugin 的 Jar 打包到具有依赖项的单个 Jar 时(如此处:How can I create an executable JAR with dependencies using Maven?),我再也看不到我的 list 条目了。我的猜测是我的 MANIFEST.MF 在程序集运行时被删除,但我找不到在 list 完成后设置它的方法。

这是我的 pom.xml 构建部分的样子:

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>

<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>

<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>ConvertorMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>${project.artifactId}</finalName>
<archive>
<manifestEntries>
<Application-Version>${app.version.major}.${app.version.minor}.0</Application-Version>
<Built-By>${user}</Built-By>
<Git-Branch>${git.branch}</Git-Branch>
<Git-Commit>${git.commit}</Git-Commit>
</manifestEntries>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
...
</build>

如果没有 jar-with-dependencies,MAINFEST.MF 将包含:

Manifest-Version: 1.0
Git-Commit: 35ff1f997b0c01daf44ed23425a3dc93307faaf7
Build-Jdk: 1.7.0_03
Built-By: Build Server
Git-Branch: origin/HEAD
Created-By: Apache Maven
Application-Version: 0.2.57
Archiver-Version: Plexus Archiver

然后,解压 -q -c convertor-1.0-jar-with-dependencies.jar META-INF/MANIFEST.MF 转储:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: eranh
Build-Jdk: 1.6.0_35
Main-Class: ConvertorMain

最佳答案

您只需将存档部分从您的 maven-jar-plugin 配置复制到 maven-assembly-plugin 中。

关于java - 构建 jar-with-dependencies 时的 ManifestEntries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12553942/

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