【发布时间】:2010-10-27 04:23:12
【问题描述】:
我设法创建了主 jar,将依赖项复制到单个目录,剩下的唯一步骤就是签署所有 jar。
我可以将自己生成的 jar 作为 jar:sign 的一部分进行签名,但我如何签署依赖项?
谢谢
【问题讨论】:
我设法创建了主 jar,将依赖项复制到单个目录,剩下的唯一步骤就是签署所有 jar。
我可以将自己生成的 jar 作为 jar:sign 的一部分进行签名,但我如何签署依赖项?
谢谢
【问题讨论】:
这里有几个选项:
【讨论】:
添加到插件配置<archiveDirectory>target</archiveDirectory>
【讨论】:
如果您使用maven-jar-plugin,您可以使用“jarPath”设置指定要签名的单个 jar。以下配置导致 jar-with-dependencies 文件被签名而不是无依赖项 jar 文件:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- NOTE: The secret key is in shared version control. The
password is in shared version control. This IS NOT
SECURE. It's intended to help avoid accidentally
loading the wrong class, nothing more. -->
<jarPath>${project.build.directory}/${project.build.FinalName}-${project.packaging}-with-dependencies.${project.packaging}</jarPath>
<keystore>${basedir}/keystore</keystore>
<alias>SharedSecret</alias>
<storepass>FOO</storepass>
</configuration>
</plugin>
如果您想同时签署两者,我不知道如何使用 maven-jar-plugin 进行签名,因此您可能需要查看上述其他选项。
【讨论】:
也可以使用 maven-assembly-plugin 创建单个 JAR。
与 Eric Anderson 的另一个建议(签署另一个 JAR)一起,然后可以签署这个组装的 JAR(而不是原始 JAR)。请注意,插件定义的顺序在这里很重要。
假设 sign.keystore.file 等设置在其他地方(例如在配置文件中)。
<build>
<plugins>
<!-- It seems that maven-assembly-plugin must be declared before the maven-jar-plugin,
so that it is executed first in the package phase,
and then the signing of the packaged jar can succeed. -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifestEntries>
<!-- ... -->
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<jarPath>${project.build.directory}/${project.build.FinalName}-${project.packaging}-with-dependencies.${project.packaging}</jarPath>
<keystore>${sign.keystore.file}</keystore>
<type>${sign.keystore.type}</type>
<storepass>${sign.keystore.storepass}</storepass>
<alias>${sign.keystore.alias}</alias>
<verify>true</verify>
<verbose>false</verbose>
<removeExistingSignatures>true</removeExistingSignatures>
</configuration>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<!-- <addClasspath>true</addClasspath> -->
</manifest>
<manifestEntries>
<!-- ... -->
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
【讨论】: