9

我设法创建了主 jar,将依赖项复制到一个目录,剩下的唯一步骤就是签署所有 jar。

我可以将自己生成的 jar 签名作为 jar:sign 的一部分,但我如何签署依赖项?

谢谢

4

4 回答 4

7

这里有几个选项:

  1. 使用 Maven ant 任务从 JDK 中针对所有依赖项运行 jarsigner。
  2. 使用可以签署所有 JAR 的webstart 插件,即使您没有将它用于 JNLP 化您的应用程序。我正在使用它来实际 JNLPize 一个应用程序。
  3. 看看 webstart 插件源正在做什么来迭代所有依赖项并对其进行签名并启动一个新的 Maven 插件/Mojo,它做同样的事情,没有 JNLP。
  4. Onejar 您的应用程序及其依赖项,然后签名。
于 2009-05-22T06:48:21.537 回答
1

添加到插件配置<archiveDirectory>target</archiveDirectory>

于 2009-12-06T18:39:40.183 回答
0

如果您正在使用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,因此您可能需要查看上面提到的其他选项。

于 2010-11-29T18:48:21.353 回答
0

还可以使用 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>
于 2013-04-24T20:58:07.870 回答