JavaFX 项目的有效 JAR 签名 [英] Valid JAR signature for JavaFX projects
问题描述
我一直在研究各种方法,以使用 Maven POM 为 JavaFX 项目生成可运行的 JAR 文件.这些 Stackoverflow 问题中的每一个都描述了相同的问题.令人沮丧的是,针对同一目标似乎有多种不同的解决方案.
I've been working through various recipes to produce a runnable JAR file for a JavaFX project 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.
问题:
java.lang.SecurityException: Manifest 主要属性的无效签名文件摘要
java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
在命令行上执行 JAR 文件时出错.虽然Netbeans可以愉快的运行程序并调试程序.
Error when executing a JAR file on the command line. Although Netbeans can happily run the program and debug the program.
诊断
有几个关于此的 Stackoverflow 和论坛问题(下面是最有用的问题).尽管是一个已知问题,但我还没有找到使用 JavaFX 的明确解决方案.这些答案中描述的过程不适用于用于捆绑 JavaFX JAR 的 JavaFxPackager 工具:
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 JavaFxPackager tool used to bundle-up your JavaFX JAR:
- 签名文件摘要无效"通过 Maven 添加 Janino 包时出错
- 错误 (org.codehaus.mojo) 何时向 Maven-Java-project 添加持久性? ... 这看起来最有前途,因为它也是一个 JavaFX 项目.到目前为止,这里也有同样的错误.
- "Invalid signature file digest" error adding Janino package through Maven
- Error (org.codehaus.mojo) when adding persistence to Maven-Java-project? ... This looks the most promising since it is also a JavaFX project. Same error here so far.
常用方法:这个问题的热门答案(撰写本文时获得 255 票):适用于我们项目中的非-JavaFX 模块:
usual approach: The post popular answer for this question (255 votes at time of writing): works with non-JavaFX modules in our project:
然而,当我们在构建 JavaFX JAR 文件的 POM 中放入相同的插件时,我们仍然得到:无效的签名文件摘要 ..."错误.具体来说,我先将
放在 JavaFxPackager exec 规则之前和之后.结果是
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
- Maven 给出:Manifest 主要属性的签名文件摘要无效..."错误
- Maven gives the: "Invalid signature file digest for Manifest main attributes..." error
**问题*:
如何设法打包 JavaFX 应用程序.这是 POM
Netbeans 为 JavaFX 设置:
How does one manage to package a JavaFX application. This is the POM <build> section
Netbeans sets-up for JavaFX:
<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
配置:无效的签名文件"尝试运行 .jar 时 目前看起来像这样:
The shard plugin
configuration used based on the answer in: "Invalid signature file" when attempting to run a .jar currently looks like this:
<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,我只运行了
To keep Netbeans out of the equation as much as possible, I just run
- mvn 包
在命令行上.这个问题似乎是一个常见问题,我希望有人破解了 JavaFX 构建的其他 JAR 文件中的 JavaFX 捆绑代码.
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.
其他链接:
推荐答案
我遇到了一个非常相似的问题;当我在项目中包含一个签名的 JAR (bouncycastle) 时.它的签名被逐字重新打包,导致明显的SecurityException:
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:
java.lang.SecurityException: 无效的签名文件摘要Manifest 主要属性
java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
各种过滤失败;对我有用的解决方案在 pom.xml 中如下所示:
Filtering of all sorts failed; the solution that works for me looks like this in the 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.
这篇关于JavaFX 项目的有效 JAR 签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!