【问题标题】:Maven jarsigner plugin configuration not workingMaven jarsigner 插件配置不起作用
【发布时间】:2018-07-20 01:56:08
【问题描述】:

我正在尝试使用以下 pom.xml 配置对 jar 文件进行签名。

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jarsigner-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>sign</id>
                        <phase>package</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <archive>${basedir}/target/ROOT.jar</archive>
                    <keystore>${basedir}/keystore.jks</keystore>
                    <alias>my_certificate_alias</alias>
                    <storepass>123456</storepass>
                    <keypass>123456</keypass>
                </configuration>
            </plugin>

keystore.jks 与 pom.xml 位于同一文件夹中。 运行“mvn clean package”后,ROOT.jar 在目标中可用。 allias 是正确的,使用的密码也是正确的。

当我使用“jarsigner -verify path\to\target\ROOT.jar”验证 jar 时

我得到“jar 未签名”。 有谁知道我的 pom 出了什么问题?

编辑:Apache Maven 3.5.2 Java 版本:1.8.0_161 完整的Pom:

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://maven.apache.org/POM/4.0.0"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.microsoft.tfs.demo</groupId>
  <artifactId>DeepSpace</artifactId>

  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Deep Space Bootcamp Sample App</name>
  <url>http://maven.apache.org</url>

  <properties>
      <mvn.compiler.version>3.0</mvn.compiler.version>
       <maven.jetty.version>6.1.12</maven.jetty.version>
      <jersey.version>2.17</jersey.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>${jersey.version}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>${jersey.version}</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${mvn.compiler.version}</version>
                <configuration>
                    <compilerArgument>-Xlint:unchecked</compilerArgument>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>${maven.jetty.version}</version>
                <configuration>
                    <scanIntervalSeconds>5</scanIntervalSeconds>
                    <contextPath>/</contextPath>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>3030</port>
                            <maxIdleTime>60000</maxIdleTime>
                            <headerBufferSize>16384</headerBufferSize>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jarsigner-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>signer</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <archive>${basedir}/target/ROOT.jar</archive>
                    <keystore>${basedir}/keystore.jks</keystore>
                    <alias>my_certificate_alias</alias>
                    <storepass>123456</storepass>
                    <keypass>123456</keypass>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <finalName>ROOT</finalName>
</build>

【问题讨论】:

    标签: java maven jarsigner jar-signing maven-jarsigner-plugin


    【解决方案1】:

    我假设完整的 POM 是正确的(它与您最初的 sn-p 不同)。

    jarsigner 声明移到&lt;pluginManagement&gt; 部分之外:

    <build>
      <pluginManagement>
         <plugins>
           ... <!-- Move the jarsigner from here -->
         </plugins>
      </pluginManagement>
      <plugins>
        <!-- To here: -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jarsigner-plugin</artifactId>
          <version>1.4</version>
          <executions>
            <execution>
              <id>signer</id>
              <phase>prepare-package</phase>
              <goals>
                <goal>sign</goal>
              </goals>
             </execution>
          </executions>
          <configuration>
            <archive>${basedir}/target/ROOT.jar</archive>
            <keystore>${basedir}/keystore.jks</keystore>
            <alias>my_certificate_alias</alias>
            <storepass>123456</storepass>
            <keypass>123456</keypass>
          </configuration>
        </plugin>
      </plugins>
    </build>
    

    接下来,将&lt;phase&gt;prepare-package 更改为package

      <execution>
        <id>signer</id>
        <phase>package</phase>  <!-- The JAR is not created in prepare-package -->
        <goals>
          <goal>sign</goal>
        </goals>
      </execution>
    

    【讨论】:

      猜你喜欢
      • 2012-05-28
      • 1970-01-01
      • 2017-08-14
      • 2019-10-04
      • 2013-07-04
      • 2018-09-03
      • 2013-05-17
      • 2017-08-15
      • 1970-01-01
      相关资源
      最近更新 更多