【问题标题】:maven javafx plugin: generate MANIFESTmaven javafx插件:生成清单
【发布时间】: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。请更新到当前版本,以便在您的项目中包含最新的解决方法/功能/错误修复。

标签: java maven javafx pom.xml


【解决方案1】:

maven-jar-plugin 配置与jfx-plugin 配置无关。事实上,他们在两个不同的位置(默认配置)创建了两个不同的 jar。

您必须将以下配置添加到您的 jfx-plugin 配置中:

<manifestAttributes>
    <Specification-Title>${project.name}</Specification-Title>
    <Specification-Version>${project.version}</Specification-Version>
    <Specification-Vendor>${project.organization.name}</Specification-Vendor>
    <Implementation-Title>${project.name}</Implementation-Title>
    <Implementation-Version>${project.version}</Implementation-Version>
    <Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
    <Implementation-Vendor>${project.organization.name</Implementation-Vendor>
</manifestAttributes>

您可以通过访问-final-jar.jar/META-INF/MANIFEST.MF 来检查这些值。

我将在插件 repo 上创建一个问题/票证,以默认添加对这些标志的支持,类似于 maven-jar-pluginjavafx-maven-plugin #220

【讨论】:

  • 你是对的,生成的 jar 文件没有任何共同点,因为它们是由不同的 maven 插件生成的。这个问题被我解决了,因为它没有真正的附加价值,特别是当拥有包含本机启动器的自包含包时。**免责声明:我是那个 javafx-maven-plugin 的维护者**
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-27
  • 2013-10-21
  • 1970-01-01
  • 1970-01-01
  • 2016-07-04
  • 2012-03-13
  • 2013-05-05
相关资源
最近更新 更多