java JavaFX 项目的有效 JAR 签名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25842559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 08:46:43  来源:igfitidea点击:

Valid JAR signature for JavaFX projects

javamavennetbeansjavafx-2maven-3

提问by will

I've been working through various recipes to produce a runnable JAR file for a JavaFXproject using a Maven POM. Each of these Stackoverflow questions describes the same problem. It is frustrating that there seems to be several different solutions for the same goal.

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

problem:

问题

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

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

Error when executing a JAR file on the command line. Although Netbeans can happily run the program and debug the program.

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

diagnosis

诊断

There are several Stackoverflow and forum questions about this (most helpful ones below). Even though is a known problem I'm yet to find a clear solution to work with JavaFX. The procedures described in these answers do NOT with the JavaFxPackagertool used to bundle-up your JavaFX JAR:

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

usual approach: The post popular answer for this question (255 votes at time of writing): works with non-JavaFX modules in our project:

通常的方法:这个问题的帖子流行答案(撰写本文时为 255 票):在我们的项目中使用-JavaFX 模块:

However when we put the same plug-in in the POM that builds the JavaFX JAR file, we still get the: "Invalid signature file digest..." error. Specifically, I placed the <artifactId>maven-shade-plugin</artifactId>first before and then after the JavaFxPackager exec rule. The result is

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

  • Maven gives the: "Invalid signature file digest for Manifest main attributes..." error
  • Maven 给出:“清单主要属性的签名文件摘要无效......”错误

**question*:

**问题*:

How does one manage to package a JavaFX application. This is the POM <build> sectionNetbeans sets-up for JavaFX:

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

The shard pluginconfiguration used based on the answer in: "Invalid signature file" when attempting to run a .jarcurrently looks like this:

当前尝试运行 .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>

To keep Netbeans out of the equation as much as possible, I just run

为了尽可能避免 Netbeans,我只是运行

  • mvn package
  • mvn 包

On the command line. This just issue seems to be a frequent problem and I'm hoping someone has cracked the code for JavFX bundling in other JAR files for a JavaFX build.

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

Other links:

其他链接

回答by foo

I had a very similar problem; when I included a signed JAR (bouncycastle) in the project. Its signature was repackaged verbatim, resulting in an obvious SecurityException:

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

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

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

Filtering of all sorts failed; the solution that works for me looks like this in the pom.xml:

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

I omitted some lines after the new one with the "excludes" pattern. This single line was the solution for me - I include the other lines so you can see the placement. (I had trouble with many other postings which omitted the context of a tag, so I try to save others this trouble).

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

Hope that helps others with the same problem.

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

回答by Elvis Del Tedesco

After a lot of research I found a solution that works for my project using JavaFX, Maven and NetBeans.

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

I'm working on a simple REST client that uses jersey and moxy to decode JSON. After adding the dependency jersey-media-moxy application reports the error of invalid signature.

我正在开发一个简单的 REST 客户端,它使用 jersey 和 moxy 来解码 JSON。添加依赖jersey-media-moxy后,应用报invalid signature的错误。

I found that this depends on the presence of the signature file ECLIPSE_.RSAand ECLIPSE_.SFinside the META-INF for some libraries. In my case were the org.eclipse.persistence.moxy-2.5.0.jar, org.eclipse.persistence.antlr-2.5.0.jar, org.eclipse.persistence.asm-2.5.0.jarand org.eclipse.persistence.core-2.5.0.jar

我发现这取决于某些库的 META-INF 中是否存在签名文件ECLIPSE_.RSAECLIPSE_.SF。在我的情况下是org.eclipse.persistence.moxy-2.5.0.jar, org.eclipse.persistence.antlr-2.5.0.jar,org.eclipse.persistence.asm-2.5.0.jarorg.eclipse.persistence.core-2.5.0.jar

The pom.xml in Netbeans that you indicated running two separate step. The first invoke maven-dependency-plugin that expands all the external jar. The second use exec-maven-plugin that call javafxpackager to create the final jar file e finally run it.

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

By performing the two steps in sequence signature in org.eclipse libraries are placed in the META-INF of the final jar file and this generates the error on the signature.

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

My solution is add an intermediate step between the execution of the maven-dependency-plugin and exec-maven-plugin. In this step I'm going to delete all signature file inside the directory

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

${project.build.directory}/classes

To do this I used a plugin maven-antrun-plugin

为此,我使用了一个插件 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>