【问题标题】:Can maven sign not only produced jar, but also dependenciesmaven不仅可以签名生成的jar,还可以签名依赖
【发布时间】:2010-10-27 04:23:12
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: maven-2 jar sign


    【解决方案1】:

    这里有几个选项:

    1. 使用 Maven ant 任务从 JDK 中针对所有依赖项运行 jarsigner。
    2. 使用可以签署所有 JAR 的 webstart plugin,即使您没有将其用于 JNLP 化您的应用程序。我正在使用它来实际 JNLPize 一个应用程序。
    3. 看看 webstart 插件源正在做什么来迭代所有依赖项并对其进行签名并启动一个新的 Maven 插件/Mojo,它做同样的事情,没有 JNLP。
    4. Onejar your app and its dependencies 并签字。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      【解决方案3】:

      如果您使用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 进行签名,因此您可能需要查看上述其他选项。

      【讨论】:

        【解决方案4】:

        也可以使用 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>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-03-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-15
          • 2018-02-28
          相关资源
          最近更新 更多