【发布时间】:2016-03-25 17:28:40
【问题描述】:
我想在运行时访问我的 pom.xml 的 ${version} 属性,使用如下代码:
primaryStage.setTitle("MyApp v" + Main.class.getPackage().getImplementationVersion());
我正在使用javafx-maven-plugin 来构建可执行jar。
知道此代码仅在找到具有 version 属性的 MANIFEST 文件时才有效,我查看了插件的文档,但没有发现任何内容可以让它生成 MANIFEST 文件。
所以接下来我尝试使用maven-jar-plugin,它应该可以完成here发布的工作。
但我仍然从上面的代码中得到MyApp vnull。
来自我的 pom.xml:
<build>
<plugins>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.4</version>
<configuration>
<mainClass>de.tools.Main</mainClass>
<identifier>${project.artifactId}</identifier>
<vendor>Me</vendor>
<bundler>EXE</bundler>
<nativeReleaseVersion>${project.version}</nativeReleaseVersion>
<needShortcut>true</needShortcut>
<needMenu>true</needMenu>
<appName>${project.artifactId}</appName>
</configuration>
<executions>
<execution>
<!-- required before build-native -->
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
<execution>
<id>create-native</id>
<phase>package</phase>
<goals>
<goal>build-native</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我做错了什么?
【问题讨论】:
-
如@ST-DDT 所述,您必须在 javafx-maven-plugin 中配置 jfx-jar。请更新到当前版本,以便在您的项目中包含最新的解决方法/功能/错误修复。