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主要属性的签名文件摘要无效
在命令行上执行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)?这看起来最有希望,因为它也是一个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:
- 无效的签名文件当试图运行.jar ...
- "Invalid signature file" when attempting to run a .jar ...
但是当我们在POM中放入相同的插件时构建JavaFX JAR文件,我们仍然得到: 无效的签名文件摘要 ...错误。具体来说,我首先在JavaFxPackager exec规则之前和之后放置< artifactId> maven-shade-plugin< / artifactId>
。结果是
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
**问题*:
如何设法打包a JavaFX应用程序。这是POM < build>部分
JavaFX的Netbeans设置:
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插件
使用的配置基于回答:无效的签名文件在尝试运行.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 package
在命令行中。这个问题似乎是一个常见的问题,我希望有人破解了JavFX捆绑其他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.
其他链接:
- How to tell the maven-shade-plugin to preserve signatures?
- Packaging jar is invalid Aggregator project need pom as packaging
- Apache Maven Shade Plug-in
- Executable JAR
推荐答案
我有一个非常类似的问题;当我在项目中包含一个签名的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屋!