2010-01-08 57 views

回答

9

这是小程序的示例pom,它依赖于其他(签名)的jar。你的applet模块的代码将打包成jar并使用测试密钥进行签名。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <parent> 
    <artifactId>parent</artifactId> 
    <groupId>com.example</groupId> 
    <version>0.1</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.example</groupId> 
    <artifactId>applet</artifactId> 
    <version>0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <name>com.example.applet</name> 
    <build> 
    <finalName>${artifactId}-${version}</finalName> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jarsigner-plugin</artifactId> 
     <executions> 
      <execution> 
      <goals> 
       <goal>sign</goal> 
      </goals> 
      <phase>package</phase> 
      <configuration> 
       <keystore>src/main/keystore/signing-jar.keystore</keystore> 
       <alias>applet</alias> 
       <storepass>applet</storepass> 
       <keypass>applet</keypass> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
    <dependencies> 
    <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>other</artifactId> 
     <version>0.4</version> 
    </dependency> 
    </dependencies> 
</project> 

这是样品shell脚本创建密钥存储区(地方和运行在您的POM文件所在的位置):

#!/bin/sh 
KEYSTORE=src/main/keystore/signing-jar.keystore 
keytool -genkey -alias applet -keystore $KEYSTORE -storepass applet -keypass applet -dname "CN=developer, OU=group 3, O=com.example, L=Somewhere, ST=Germany, C=DE" 
keytool -selfcert -alias applet -keystore $KEYSTORE -storepass applet -keypass applet 

MVN包后,你将有你的签字com.example.applet- 0.1-SNAPSHOT.jar。将它与您的依赖关系(com.example.other-0.4.jar)放在您的Web应用程序中。

10

如果你想你的类的依赖出现在一个jar文件,你应该使用的assembly pluginjarsignerone-jar plugin。我使用程序集插件进行以下工作设置,它将生成正常(签名)的jar和$ {artifactId} - $ {version} -jar-with-dependencies.jar(也已签名)。

  <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2-beta-5</version> 
      <configuration> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
       <archive> 
        <index>true</index> 
        <manifest> 
         <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 
        </manifest> 
       </archive> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-my-applet-jar</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <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>keystore</keystore> 
       <alias>keyalias</alias> 
       <storepass>storepass</storepass> 
       <keypass>keypass</keypass> 
      </configuration> 
     </plugin> 
+2

maven-shade-plugin也是一个选项,用于生成一个具有类路径中所有可用依赖项的单个可执行JAR。主要区别在于阴影插件包含所有依赖项和嵌入的.class文件,而不是嵌入式JAR。 – 2010-12-02 19:23:10

+0

任何大于2.2-beta-5的maven-assembly-plugin版本都会崩溃。 – 2014-04-18 12:43:48