我正在尝试将构建服务器信息设置为META-INF / MANIFEST.MF。当使用带有manifestEntries的maven-jar-plugin时,它非常有效。问题是当我将带有maven-assembly-plugin的Jar打包到一个带有依赖关系的Jar时(比如这里:How can I create an executable JAR with dependencies using Maven?)我再也看不到我的清单条目了。我的猜测是我的MANIFEST.MF在程序集运行时被删除了,但是在清单完成后我找不到设置它的方法。
这就是我的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
然后,unzip -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
答案 0 :(得分:2)
您只需将maven-jar-plugin配置中的存档部分复制到maven-assembly-plugin中。