JavaFX项目的有效JAR签名

时间:2014-09-15 07:09:40

标签: java maven netbeans javafx-2 maven-3

我一直在使用各种配方为使用Maven POM的 JavaFX 项目生成可运行的JAR文件。这些Stackoverflow问题中的每一个都描述了同样的问题。令人沮丧的是,针对同一目标似乎有几种不同的解决方案。

问题

  

java.lang.SecurityException: Manifest主要属性的签名文件摘要无效

在命令行上执行JAR文件时出错。虽然Netbeans可以愉快地运行程序并调试程序。

诊断

有几个Stackoverflow和论坛问题(下面最有用的)。即使已知问题,我还没有找到一个明确的解决方案来使用JavaFX。这些答案中描述的过程不是用于捆绑JavaFX JAR的 JavaFxPackager 工具:

常用方法: 该帖子的热门答案(撰写本文时为255票):在我们的项目中使用 -JavaFX模块:

但是,当我们在构建JavaFX JAR文件的POM中放入相同的插件时,我们仍然会得到:&#34; 无效的签名文件摘要 。 ..&#34;错误。具体来说,我先将<artifactId>maven-shade-plugin</artifactId>放在JavaFxPackager exec规则之前和之后。结果是

  • Maven提供:&#34; Manifest主要属性的无效签名文件摘要 ...&#34;错误

**问题*:

如何管理JavaFX应用程序。这是JavaFX的POM <build> section Netbeans设置:

      <build>
          <resources>
             <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
             </resource>
          </resources>

          <plugins>
             <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-dependency-plugin</artifactId>
                  <version>2.8</version>
                  <executions>
                      <execution>
                          <id>unpack-dependencies</id>
                          <phase>package</phase>
                          <goals>
                              <goal>unpack-dependencies</goal>
                          </goals>
                          <configuration>
                              <excludeScope>system</excludeScope>
                              <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
                              <outputDirectory>${project.build.directory}/classes</outputDirectory>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>

              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>exec-maven-plugin</artifactId>
                  <version>1.3.2</version>
                  <executions>
                      <execution>
                          <id>unpack-dependencies</id>
                          <phase>package</phase>
                          <goals>
                              <goal>exec</goal>
                          </goals>
                          <configuration>
                              <executable>${java.home}/../bin/javafxpackager</executable>
                              <arguments>
                                  <argument>-createjar</argument>
                                  <argument>-nocss2bin</argument>
                                  <argument>-appclass</argument>
                                  <argument>${mainClass}</argument>
                                  <argument>-srcdir</argument>
                                  <argument>${project.build.directory}/classes</argument>
                                  <argument>-outdir</argument>
                                  <argument>${project.build.directory}</argument>
                                  <argument>-outfile</argument>
                                  <argument>${project.build.finalName}.jar</argument>
                              </arguments>
                          </configuration>
                      </execution>
                      <execution>
                          <id>default-cli</id>
                          <goals>
                              <goal>exec</goal>
                          </goals>
                          <configuration>
                              <executable>${java.home}/bin/java</executable>
                              <commandlineArgs>${runfx.args}</commandlineArgs>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>

              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.1</version>
                  <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                      <compilerArgument>-Xlint:unchecked</compilerArgument>  <!-- all -->
                      <showWarnings>true</showWarnings>
                      <showDeprecation>true</showDeprecation>
                      <compilerArguments>
                          <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib      /jfxrt.jar</bootclasspath>
                      </compilerArguments>
                  </configuration>
              </plugin>

              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>2.16</version>
                  <configuration>
                      <additionalClasspathElements>
                          <additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
                      </additionalClasspathElements>
                  </configuration>
              </plugin>
          </plugins>
      </build>

根据"Invalid signature file" when attempting to run a .jar中的答案使用的shard plugin配置目前如下所示:

              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-shade-plugin</artifactId>
                      <!--    http://maven.apache.org/plugins/maven-shade-plugin/     -->
                      <!--    http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin -->
                      <!--    http://zhentao-li.blogspot.com.au/2012/06/maven-shade-plugin-invalid-signature.html     -->
                  <version>2.3</version>
                  <executions>
                      <execution>
                        <id>remove-sign-files</id>
                        <phase>package</phase>
                        <goals>
                          <goal>shade</goal>
                        </goals>
                        <configuration>
                          <filters>
                              <filter>
                                  <artifact>*:*</artifact>
                                  <excludes>
                                      <exclude>classes/META-INF/*.SF</exclude>
                                      <exclude>classes/META-INF/*.DSA</exclude>
                                      <exclude>classes/META-INF/*.RSA</exclude>
                                  </excludes>
                              </filter>
                          </filters>
                        </configuration>
                      </execution>
                  </executions>
              </plugin>

为了尽可能地让Netbeans脱离等式,我只是运行

  • mvn package

在命令行上。这个问题似乎是一个经常出现的问题,我希望有人破解了JavFX捆绑其他JAR文件中的JavaFX构建代码。

其他链接

2 个答案:

答案 0 :(得分:15)

我有一个非常相似的问题;当我在项目中包含一个签名的JAR(bouncycastle)时。它的签名被逐字重新打包,导致明显的SecurityException:

  

java.lang.SecurityException:无效的签名文件摘要   清单主要属性

过滤所有类别的失败;适合我的解决方案在pom.xml中看起来像这样:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.8</version>
  <executions>
    <execution>
      <id>unpack-dependencies</id>
      <phase>package</phase>
      <goals>
        <goal>unpack-dependencies</goal>
      </goals>
      <configuration>
        <excludes>META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA</excludes>
        ...
      </configuration>
    </execution>
  </executions>
</plugin>

我在&#34之后省略了一些新的行;排除&#34;图案。 这条单线是我的解决方案 - 我包括其他线,以便您可以看到位置。 (我在许多其他帖子中省略了标签的上下文时遇到了麻烦,所以我试图将其他问题保存起来。)

希望能帮助其他人解决同样的问题。

答案 1 :(得分:1)

经过大量研究后,我找到了一个适用于我的项目的解决方案,使用JavaFX,Maven和NetBeans。

我正在使用一个简单的REST客户端,它使用jersey和moxy来解码JSON。 添加依赖项后,jersey-media-moxy应用程序报告无效签名的错误。

我发现这取决于某些库中META-INF内是否存在签名文件 ECLIPSE_.RSA ECLIPSE_.SF 。 就我而言,org.eclipse.persistence.moxy-2.5.0.jarorg.eclipse.persistence.antlr-2.5.0.jarorg.eclipse.persistence.asm-2.5.0.jarorg.eclipse.persistence.core-2.5.0.jar

您指示运行两个单独步骤的Netbeans中的pom.xml。 第一个调用maven-dependency-plugin,扩展了所有外部jar。 第二个使用exec-maven-plugin调用javafxpackager来创建最终的jar文件,最后运行它。

通过在org.eclipse中执行序列签名中的两个步骤,库被放置在最终jar文件的META-INF中,这会在签名上生成错误。

我的解决方案是在执行maven-dependency-plugin和exec-maven-plugin之间添加一个中间步骤。在此步骤中,我将删除目录

中的所有签名文件
${project.build.directory}/classes

为此,我使用了插件maven-antrun-plugin

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
         <execution>
              <phase>package</phase>
              <goals>
                   <goal>run</goal>
              </goals>
              <configuration>
                   <target>
                       <delete>
                           <fileset dir="${project.build.directory}/classes" includes="**/META-INF/*.DSA"/>
                           <fileset dir="${project.build.directory}/classes" includes="**/META-INF/*.RSA"/>
                           <fileset dir="${project.build.directory}/classes" includes="**/META-INF/*.SF"/>
                    </delete>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>