简体   繁体   English

Maven jarsigner插件配置不起作用

[英]Maven jarsigner plugin configuration not working

I am trying to sign a jar file with the following pom.xml config. 我正在尝试使用以下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 is located in the same folder as the pom.xml. keystore.jks与pom.xml位于同一文件夹中。 ROOT.jar is available in target after running "mvn clean package". 运行“ mvn clean package”后,ROOT.jar在目标中可用。 allias is correct and so are the passwords used. allias是正确的,使用的密码也是正确的。

When I verify the jar with "jarsigner -verify path\\to\\target\\ROOT.jar" 当我使用“ jarsigner -verify path \\ to \\ target \\ ROOT.jar”验证罐子时

I get "jar is unsigned." 我得到“ jar未签名”。 Does anyone have a clue what is wrong with my pom? 有人知道我pom怎么了吗?

Edit: Apache Maven 3.5.2 Java version: 1.8.0_161 Full Pom: 编辑:Apache Maven 3.5.2 Java版本:1.8.0_161 Full 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>

I am assuming that the full POM is the correct one (it differs from your initial snippet). 我假设完整的POM是正确的(它与您的原始代码段不同)。

Move the jarsigner declaration outside the <pluginManagement> section: jarsigner声明<pluginManagement>部分之外:

<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>

Next, change the <phase> from prepare-package to package : 接下来,将<phase>prepare-package更改为package

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM