JNLP规范说,可以通过将JNLP文件包含在JNLP应用程序的主jar(它本身必须被签名)中来对JNLP文件本身进行签名。有人知道如果maven-webstart-plugin可以做到这一点吗?
JNLP签名(自动生成应用程序)。JNLP或APPLICATION_TEMPLATE.JNLP)可以通过几个maven插件的组合来完成。通常webstart-maven-plugin会完成所有的工作,包括在maven模块中打包工件(例如zip文件)。执行JNLP签名的关键是将此任务分成几个步骤:
A) for APPLICATION。JNLP代:
- 生成jnlp并签署所有库(包括清单项)使用webstart-maven-plugin 更新到/target/jnlp目录
- 复制,将JNLP文件从/target/JNLP dir重命名为目标/jnlp/main.jar/JNLP-INF/应用程序。JNLP与truezip-maven-plugin 在target/jnlp/main.jar中反复签名main.jar文件maven-jarsigner-plugin
- package/target/jnlp目录到工件,例如withmaven-war-plugin或maven-assembly-plugin
B) for APPLICATION_TEMPLATE。JNLP生成(1分)和2。不同于前面的步骤):
- 同时生成:jnlp,APPLICATION_TEMPLATE。JNLP和签名全部库(包括清单项更新)到目录/target/jnlp使用webstart-maven-plugin
- APPLICATION_TEMPLATE移动。JNLP文件//jnlp/APPLICATION_TEMPLATE目标。JNLP到target/JNLP/main.jar/JNLP- inf/APPLICATION_TEMPLATE。使用truezip-maven-plugin
- 使用maven-jarsigner-plugin 对target/jnlp/main.jar中的main.jar文件重复签名
- package/target/jnlp目录到工件,例如withmaven-war-plugin或maven-assembly-plugin
注1:main.jar文件被签名两次(在步骤1和步骤3中),与在步骤3中使用maven-jarsigner-plugin对所有jar文件只签名一次相比,这是开销。但是我们需要它这样做,因为webstart-maven-plugin只更新配置签名的manifest文件(带有权限头)。
注2:当你的webstart应用程序有许多不同的构建配置文件时,这种方法非常有效,因为application。JNLP或APPLICATION_TEMPLATE。JNLP是基于您的配置文件自动生成的。
注释3:我花了超过一天半的时间来开发和测试这种方法,希望它能让你的生活更轻松;)
下面是两种JNLP签名的一些pom.xml部分。
A) for APPLICATION。JNLP代:
<project ....>
...
<build>
<plugins>
<plugin>
<!-- Step 1) your obvious configuration, also with signing,
assume that generated jnlp file has name: launch.jnlp -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-jnlp-and-sign-libs</id>
<phase>generate-resources</phase>
<goals>
<goal>jnlp-inline</goal>
</goals>
...
</execution>
</executions>
...
</plugin>
<plugin>
<!-- Step 2) copy & rename of jnlp to APPLICATION_JNLP in main.jar -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>truezip-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>copy-jnlp-template</id>
<goals>
<goal>copy</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<files>
<file>
<source>${project.build.directory}/jnlp/launch.jnlp</source>
<outputDirectory>${project.build.directory}/jnlp/main.jar/JNLP-INF</outputDirectory>
<destName>APPLICATION.JNLP</destName>
</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Step 3) repeat signing of main.jar -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>sign</id>
<phase>prepare-package</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<archiveDirectory>${project.build.directory}/jnlp</archiveDirectory>
<includes>
<include>main.jar</include>
</includes>
<keystore>...</keystore>
<storepass>...</storepass>
<alias>...</alias>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<!-- Step 4) custom packaging -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
...
<webResources>
<resource>
<directory>${project.build.directory}/jnlp</directory>
</resource>
...
</webResources>
...
</configuration>
</plugin>
</build>
</project>
B) for APPLICATION_TEMPLATE。JNLP代:
<project ....>
...
<build>
<plugins>
<plugin>
<!-- Step 1) your obvious configuration + added one new execution
for APPLICATION_TEMPLATE.jnlp file generation from template stored
in /templates/APPLICATION_TEMPLATE.jnlp dir -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<executions>
<execution>
<!-- This is new execution block, don't be afraid,
inspite of multiple executions
signing and manifest update is performed only once -->
<id>generate-jnlp-template-for-signing</id>
<phase>generate-resources</phase>
<goals>
<goal>jnlp-inline</goal>
</goals>
<configuration>
<jnlp>
<inputTemplateResourcePath>${project.basedir}/templates
</inputTemplateResourcePath>
<inputTemplate>APPLICATION_TEMPLATE.jnlp</inputTemplate>
<outputFile>APPLICATION_TEMPLATE.jnlp</outputFile>
<mainClass>...</mainClass>
</jnlp>
</configuration>
</execution>
<execution>
<id>generate-jnlp-and-sign-libs</id>
<phase>generate-resources</phase>
<goals>
<goal>jnlp-inline</goal>
</goals>
<configuration>
<jnlp>
<!-- JNLP settings from your obvious configuration -->
...
</jnlp>
</configuration>
...
</execution>
</executions>
...
</plugin>
<plugin>
<!-- Step 2) move to APPLICATION_TEMPLATE from /target/jnlp
to target/jnlp/main.jar/JNLP-INF dir -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>truezip-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>move-jnlp-template</id>
<goals>
<goal>move</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<from>${project.build.directory}/jnlp/APPLICATION_TEMPLATE.jnlp
</from>
<to>${project.build.directory}/jnlp/lib/main.jar/JNLP-INF/APPLICATION_TEMPLATE.jnlp
</to>
</configuration>
</execution>
</executions>
</plugin>
<!-- Steps 3) and 4) are same as in previous code block -->
</build>
</project>
基于MWEBSTART-176,这看起来像是一个已被请求但尚未(尚未)实现的功能。