2012-07-08 111 views
3

我想構建一個程序集並簽名。我的問題是,jarsigner簽署不是程序集,只有獨立的jar文件。你能告訴我什麼問題?在使用Ant多年後,Maven對我來說似乎是「魔術」......我看不到插件合作的方式並將信息傳遞給對方。簽署使用maven-assembly插件創建的jar文件

執行mvn install後,我得到兩個jar文件,一個叫example-1.0.0-SNAPSHOT.jar,這是簽名,一個叫example-1.0.0-jar-with-dependencies.jar,這是不簽名。我不需要獨奏,只有大會,但簽署。

這裏是我的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> 

回答

4

你應該儘量把Maven的組裝插件安裝到準備封裝階段,而不是包階段:

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

我做了這個改變,從那時起我得到一個錯誤:'Embedded error:The source must not成爲一個目錄。' – jabal 2012-07-08 17:15:53

+0

你可以發佈完整的輸出到pastebin或類似的東西嗎? – khmarbaise 2012-07-09 06:49:48

+0

@khmarbaise:+1爲我排序非常感謝 – 2012-07-23 07:05:16

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

請參閱http://maven.apache.org/plugins/maven-jarsigner-plugin/sign-mojo.html