java 对使用 maven-assembly 插件创建的 jar 文件进行签名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11384704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:52:00  来源:igfitidea点击:

Sign a jar file created with maven-assembly plugin

javamavenjar-signing

提问by jabal

I'd like to build an assembly and then sign it. My problem is that the jarsigner signs not the assembly, only the standalone jar file. Could you tell me what is the problem? Maven seems like 'magic' to me after having used Ant for years.. I can't see the way the plugins cooperate and pass information to each other.

我想建立一个程序集,然后签名。我的问题是 jarsigner 不是对程序集进行签名,而是对独立的 jar 文件进行签名。你能告诉我有什么问题吗?使用 Ant 多年后,Maven 对我来说似乎是“魔法”。我看不到插件合作和相互传递信息的方式。

After executing mvn install, I get two jar files, one called example-1.0.0-SNAPSHOT.jarand this is signed, and one called example-1.0.0-jar-with-dependencies.jarand this is not signed. I do not need the solo one, only the assembly, but that signed.

执行后mvn install,我得到两个 jar 文件,一个被调用example-1.0.0-SNAPSHOT.jar并且这个被签名,一个被调用example-1.0.0-jar-with-dependencies.jar并且这个没有签名。我不需要独奏,只需要程序集,但已签名。

Here is my pom.xml:

这是我的 pom.xml:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jarsigner-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <id>sign</id>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <keystore>${project.basedir}\keystore\mykeystore</keystore>
                    <alias>myalias</alias>
                    <storepass>...</storepass>
                    <keypass>...</keypass>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>make-my-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.example.FooBar</mainClass>
                        </manifest>
                    </archive>
                    <appendAssemblyId>true</appendAssemblyId>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>

采纳答案by khmarbaise

You should try to put the maven-assembly-plugin into the prepare-package phase instead of the package phase:

您应该尝试将 maven-assembly-plugin 放入 prepare-package 阶段而不是 package 阶段:

  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <id>make-my-assembly</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
    ...
</plugin>

回答by arulraj.net

    <configuration>
        <archiveDirectory>${project.build.directory}</archiveDirectory>
        <includes>
           <include>*.jar</include>
        </includes>
        <keystore>${project.basedir}/keystore/mykeystore</keystore>
        <alias>keyalias</alias>
        <storepass>storepass</storepass>
        <keypass>keypass</keypass>
    </configuration>

Refer this http://maven.apache.org/plugins/maven-jarsigner-plugin/sign-mojo.html

参考这个http://maven.apache.org/plugins/maven-jarsigner-plugin/sign-mojo.html

回答by dzolo

Change order of plugins in your POM. Order is relevant in Maven. Run mvn installagain and review output log. You should be able to see the order of actions from the log.

更改 POM 中插件的顺序。顺序在 Maven 中是相关的。mvn install再次运行并查看输出日志。您应该能够从日志中看到操作的顺序。