Maven 2 maven不仅可以签名生成的jar,还可以签名依赖项吗

Maven 2 maven不仅可以签名生成的jar,还可以签名依赖项吗,maven-2,jar,sign,Maven 2,Jar,Sign,我设法创建了主jar,将依赖项复制到单个目录,剩下的唯一一步就是对所有jar进行签名 我可以将自己生成的jar作为jar:sign的一部分进行签名,但是如何对依赖项进行签名呢 谢谢这里有几个选项: 使用Maven ant任务针对所有依赖项从JDK运行jarsigner 使用可以对所有JAR进行签名的,即使您不是为了应用程序的JNLP而使用它。我正在使用它来实际JNLPize一个应用程序 看看webstart插件源代码是如何迭代所有依赖项并对它们进行签名的,然后启动一个新的Maven插件/Mojo

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

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


谢谢这里有几个选项:

  • 使用Maven ant任务针对所有依赖项从JDK运行jarsigner
  • 使用可以对所有JAR进行签名的,即使您不是为了应用程序的JNLP而使用它。我正在使用它来实际JNLPize一个应用程序
  • 看看webstart插件源代码是如何迭代所有依赖项并对它们进行签名的,然后启动一个新的Maven插件/Mojo,它也做同样的事情,即sans JNLP
  • 签字就行了

  • 添加到插件配置
    target

    如果您使用的是
    maven-jar-plugin
    ,则可以使用“jarPath”设置指定要签名的单个jar。以下配置导致对具有依赖项的jar文件进行签名,而不是对无依赖项的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插件
    签名
    组装
    包裹
    签名
    ${project.build.directory}/${project.build.FinalName}-${project.packaging}-带依赖项。${project.packaging}
    ${basedir}/keystore
    共享秘密
    福
    

    如果您想同时签署这两个文件,我不知道如何使用
    maven jar插件
    ,因此您可能需要研究上面提到的其他选项。

    也可以使用maven assembly插件创建一个jar

    再加上Eric Anderson(关于签署另一个JAR)的其他建议,我们可以签署这个组装好的JAR(而不是原来的JAR)。请注意,插件定义的顺序在这里很重要

    假定sign.keystore.file等设置在其他位置(例如在配置文件中)

    
    maven汇编插件
    2.4
    带有依赖项的jar
    组装
    包裹
    单一的
    org.apache.maven.plugins
    maven jar插件
    2.4
    罐子
    组装
    包裹
    签名
    ${project.build.directory}/${project.build.FinalName}-${project.packaging}-带依赖项。${project.packaging}
    ${sign.keystore.file}
    ${sign.keystore.type}
    ${sign.keystore.storepass}
    ${sign.keystore.alias}
    真的
    假的
    真的
    
    这将是一个jarsigner插件参数(),但target不是一个好值。目标目录与所需jar的根目录不对应。
    <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>