How to deploy Applet with dependencies jar using maven and sign it?

冷暖自知 提交于 2020-01-10 08:54:10

问题


Can someone show me how pom file should look like to create a jar file with applet which depends from some other jars is it possible to have one jar as applet, and how to sign it?


回答1:


If you would like your classes and the dependencies to appear in one jar file, you should use either the assembly plugin or the one-jar plugin before the jarsigner. I have the following working setup with the assembly plugin, it will produce the normal (signed) jar and a ${artifactId}-${version}-jar-with-dependencies.jar (also signed).

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


This is sample pom for applet with dependency on other (signed) jar. Code of your applet module will be packaged into jar and signed using test key.

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

This is sample shell script to create key store (place and run it where your pom file is located):

#!/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

After mvn package you will have your signed com.example.applet-0.1-SNAPSHOT.jar. Place it together with your dependency (com.example.other-0.4.jar) in your web-application.



来源:https://stackoverflow.com/questions/2027753/how-to-deploy-applet-with-dependencies-jar-using-maven-and-sign-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!