【发布时间】:2014-11-08 15:44:19
【问题描述】:
我一直在研究各种方法,使用 Maven POM 为 JavaFX 项目生成可运行的 JAR 文件。这些 Stackoverflow 问题中的每一个都描述了相同的问题。令人沮丧的是,同一目标似乎有几种不同的解决方案。
问题:
java.lang.SecurityException: Manifest 主要属性的签名文件摘要无效
在命令行上执行 JAR 文件时出错。虽然 Netbeans 可以愉快地运行程序并调试程序。
诊断
有几个关于此的 Stackoverflow 和论坛问题(最有帮助的问题如下)。尽管这是一个已知问题,但我还没有找到使用 JavaFX 的明确解决方案。这些答案中描述的过程不适用于用于捆绑 JavaFX JAR 的 JavaFxPackager 工具:
- "Invalid signature file digest" error adding Janino package through Maven
- Error (org.codehaus.mojo) when adding persistence to Maven-Java-project? ... 这看起来最有前途,因为它也是一个 JavaFX 项目。到目前为止同样的错误。
常用方法: 这个问题的热门答案(在撰写本文时有 255 票):在我们的项目中使用 non-JavaFX 模块:
但是,当我们将相同的插件放入构建 JavaFX JAR 文件的 POM 中时,我们仍然会得到:“无效的签名文件摘要 ...”错误。具体来说,我将<artifactId>maven-shade-plugin</artifactId> 先放在JavaFxPackager exec 规则之前,然后放在它之后。结果是
- Maven 给出:“Manifest 主要属性的签名文件摘要无效...”错误
**问题*:
如何打包 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 包
在命令行上。这个问题似乎是一个常见问题,我希望有人已经破解了 JavaFX 构建的其他 JAR 文件中的 JavFX 捆绑代码。
其他链接:
【问题讨论】:
标签: java maven netbeans javafx-2 maven-3