2

I want to access ${version} property of my pom.xml at runtime, using code like this:

primaryStage.setTitle("MyApp v" + Main.class.getPackage().getImplementationVersion());

I am using the javafx-maven-plugin to build the executable jar. Knowing that this code only works when MANIFEST file with version property is found, I looked in the documentation of the plugin but found nothing to let it generate the MANIFEST file.
So next I tried to use the maven-jar-plugin which should do the job as posted here.
But I still get MyApp vnull from the above code.

From my 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>

What am I doing wrong?

Community
  • 1
  • 1
lenny
  • 2,978
  • 4
  • 23
  • 39
  • As stated by @ST-DDT, you have to configure the jfx-jar inside the javafx-maven-plugin. Please update to the current version for having latest workarounds/features/bugfixes inside your project. – FibreFoX Aug 04 '16 at 20:15

1 Answers1

1

The maven-jar-plugin configuration has nothing to do with the jfx-plugin configuration. In fact they create two distinct jars at two distinct locations (default config).

You have to add the following configuration to your jfx-plugin config:

<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>

You can check these values by accessing the-final-jar.jar/META-INF/MANIFEST.MF.

I will create an issue/ticket on the plugins repo to add support for these flags by default similar to the maven-jar-plugin: javafx-maven-plugin #220

ST-DDT
  • 2,615
  • 3
  • 30
  • 51
  • 1
    You are right, the generated jar-files don't have anything in common, because they are produced by different maven-plugins. That issue was closed by me, because there is no real added value for this, especially when having self-containing bundles containing native launchers.**Disclaimer: I'm the maintainer of that javafx-maven-plugin** – FibreFoX Aug 04 '16 at 20:13