maven javafx插件:生成MANIFEST

时间:2016-03-25 17:28:41

标签: java maven javafx pom.xml

我想在运行时访问我的pom.xml的${version}属性,使用如下代码:

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

我正在使用javafx-maven-plugin来构建可执行jar。 知道这个代码只有在找到带有版本属性的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>

我做错了什么?

1 个答案:

答案 0 :(得分:1)

<script> $(function () { var source = sessionStorage.getItem("source"); $("#background").attr("src", source); }); setTimeout(function () { var myImg = document.querySelector("#background"); var realWidth = myImg.naturalWidth; var realHeight = myImg.naturalHeight; $("canvas").attr("width", realWidth); $("canvas").attr("height", realHeight); var source = document.getElementById('background').src; var canvas = new fabric.Canvas('canvas'); canvas.width=realWidth; canvas.height=realHeight; var ctx = canvas.getContext('2d'); var img = new Image(); img.src = 'images/logo.png'; var imgInstance = new fabric.Image(img, { width: 200 , height: 45 }); canvas.add(imgInstance); canvas.setBackgroundImage(source, canvas.renderAll.bind(canvas), { backgroundImageOpacity: 0.5 , backgroundImageStretch: false }); }, 2000); $("#save").click(function(){ function blobCallback(iconName) { return function (b) { var a = document.getElementById('download'); a.download = iconName + ".jpg"; a.href = window.URL.createObjectURL(b); } } canvas.toBlob(blobCallback('wallpaper'), 'image/vnd.microsoft.jpg', '-moz-parse-options:format=bmp;bpp=32'); }); 配置与maven-jar-plugin配置无关。事实上,他们在两个不同的位置创建了两个不同的jar(默认配置)。

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

jfx-plugin

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

我将在插件仓库上创建一个问题/故障单,默认情况下添加对这些标志的支持,类似于<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> javafx-maven-plugin #220