maven-webstart-plugin可以签署JNLP文件本身吗?

时间:2013-05-15 15:57:20

标签: java jnlp sign maven-webstart-plugin

JNLP规范说,可选地,JNLP文件本身可以通过将其包含在JNLP应用程序的主jar(它本身必须签名)中进行签名。有谁知道maven-webstart-plugin是否可以这样做?

2 个答案:

答案 0 :(得分:4)

基于MWEBSTART-176,这看起来像是已经请求但尚未实现的功能。

答案 1 :(得分:4)

JNLP签名(自动生成APPLICATION.JNLP或APPLICATION_TEMPLATE.JNLP)可以通过组合多个maven插件来完成。通常,webstart-maven-plugin完成整个工作,包括在maven模块中打包工件(例如zip文件)。进行JNLP签名的关键是将此任务分为几个步骤:

A)APPLICATION.JNLP生成:

  1. 生成jnlp并签名所有库(包括清单条目 使用webstart-maven-plugin更新到目录/ target / jnlp
  2. copy&从/ target / jnlp目录重命名jnlp文件 target / jnlp / main.jar / JNLP-INF / APPLICATION.JNLP with truezip-行家-插件
  3. 在target / jnlp / main.jar中重复签署main.jar文件 行家-的jarsigner-插件
  4. package / target / jnlp目录到工件,例如同 maven-war-plugin或maven-assembly-plugin
  5. B)用于APPLICATION_TEMPLATE.JNLP生成(第1点和第2点与前面的步骤不同):

    1. 同时生成:jnlp,APPLICATION_TEMPLATE.JNLP并全部签名 库(包括清单条目更新)到目录 / target / jnlp with webstart-maven-plugin
    2. 从中移动APPLICATION_TEMPLATE.JNLP文件 /target/jnlp/APPLICATION_TEMPLATE.JNLP to target / jnlp / main.jar / JNLP-INF / APPLICATION_TEMPLATE.JNLP with truezip-maven-plugin
    3. 使用maven-jarsigner-plugin在/ target / jnlp / main.jar中重复签署main.jar文件
    4. package / target / jnlp目录到工件,例如同 maven-war-plugin或maven-assembly-plugin
    5. 注1:main.jar文件被签名两次(在步骤1中)和3)),这与通过maven-jarsigner-plugin在步骤3)中仅对所有jar进行一次签名进行比较是开销。但我们需要这样做,因为webstart-maven-plugin只有配置的签名才能更新清单文件(带有权限标题)。

      注意2:当您的webstart应用程序具有许多不同的构建配置文件时,此方法非常有效,因为APPLICATION.JNLP或APPLICATION_TEMPLATE.JNLP是根据您的配置文件自动生成的。

      注3:开发和测试这种方法需要一天半的时间,希望它能让你的生活更轻松;)

      下面是两种类型的JNLP签名的一些pom.xml部分。

      A)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)申请LAB_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>