java - JavaFX 项目的有效 JAR 签名

标签 java maven netbeans javafx-2 maven-3

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

问题:

java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

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

诊断

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

常用方法: 此问题的热门答案(撰写本文时获得 255 票):适用于我们项目中的-JavaFX 模块:

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

  • Maven 给出:“ list 主要属性的签名文件摘要无效...”错误

**问题*:

如何设法打包 JavaFX 应用程序。这是 POM <build> section JavaFX 的 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>

shard plugin根据以下答案使用的配置:"Invalid signature file" when attempting to run a .jar目前看起来像这样:

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

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

其他链接:

最佳答案

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

java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

各种过滤失败;对我有用的解决方案在 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>

我在带有“排除”模式的新行之后省略了一些行。 这条线是我的解决方案——我包括其他线,这样你就可以看到位置。 (我在处理许多其他省略标签上下文的帖子时遇到了麻烦,所以我尽量为其他人省去这个麻烦)。

希望对遇到同样问题的其他人有所帮助。

关于java - JavaFX 项目的有效 JAR 签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25842559/

相关文章:

java - mysql的搜索条件

java - Maven Flyway 发现非空架构 "PUBLIC"但没有架构历史表

mysql - 如何使用虚拟实体数据预填充数据库?

java - 将提供的依赖项中的特定包添加到 jar 中

c++ - 使用第三方库 : SFML 时 Netbeans 无法加载共享库

java - 如何将 log4j 输出消息分配给变量

Java Rest API 调用另一个 Rest 而不等待响应 - 在 JAX-RS 中

java - Netbeans JSR-296、Swing 和 JavaFX,我们现在打算使用什么?

java - 在 while 语句中使用 boolean 变量

netbeans - 你能像在 Visual Studio 中一样在 Netbeans 中设置某种自定义代码折叠吗