JavaFX的罐子依赖捆绑 [英] JavaFX jar with dependencies bundled

查看:382
本文介绍了JavaFX的罐子依赖捆绑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚作出了一个问题,关于使用到的javafxpackager使JavaFX的罐子,你可以看到它的here.我的问题是,我可以不包括在清单中的类路径。好吧,当我在等待答案,我试过 Maven的antrun-插件来代替。它的工作不错,我可以运行我的依赖应用程序,但(总是有但是)只有依赖超出了我最后的罐子。因此,它是这样的:

  FinalJar.jar
LIB
  | _ {这里所有的依赖}

我的清单文件指向通过 JavaFX的类路径属性的依赖关系。如果我把依赖罐子里面,就像我想要的,它没有找到我的依赖关系。任何帮助吗?

编辑:这里的步骤依赖添加到罐子,其内部的pom.xml:

 <&插件GT;
            <&的groupId GT; org.apache.maven.plugins< /的groupId>
            <&的artifactId GT;的maven-antrun-插件< / artifactId的>
            <&版GT; 1.6 LT; /版本>
            <&执行GT;
                <执行与GT;
                    <阶段>包装及LT; /阶段>
                    <结构>
                        <目标>
                            <的taskdef NAME =jfxjar类名=com.sun.javafx.tools.ant.FXJar
                                classpathref =maven.plugin.classpath/>
                            < jfxjar
                                destfile =$ {} project.build.directory / DIST / $ {} project.build.finalName>
                                <文件集DIR =$ {} project.build.directory /班/>                                <! - 添加依赖关系罐子 - >
                                <文件集DIR =$ {} project.build.directory / lib目录/包括=*罐子。/>
                                <应用NAME =$ {} project.namemainClass =com.google code.mzplay.principal.PrincipalFX。/>                                <资源>
                                    <! - 增加的依赖性类路径 - >
                                    <文件集DIR =$ {} project.build.directory / lib目录/包括=*罐子。/>
                                < /资源>
                            < / jfxjar>
                        < /目标与GT;
                    < /结构>
                    <目标>
                        <&目标GT;运行< /目标>
                    < /目标>
                < /执行>
            < /处决>
            <依赖和GT;
                <&依赖性GT;
                    <&的groupId GT; com.oracle< /的groupId>
                    <&的artifactId GT;蚂蚁的JavaFX< / artifactId的>
                    <&版GT; $ {javafx.version}< /版本>
                    < Systempath下> $ {java.home} /../的lib /蚁javafx.jar< / Systempath下>
                    <&范围GT;系统和LT; /&范围GT;
                < /依赖性>
                <&依赖性GT;
                    <&的groupId GT; com.oracle< /的groupId>
                    <&的artifactId GT;的JavaFX< / artifactId的>
                    <&版GT; $ {javafx.version}< /版本>
                    &LT; Systempath下&GT; $ {java.home} /lib/jfxrt.jar</systemPath>
                    &LT;&范围GT;系统和LT; /&范围GT;
                &LT; /依赖性&GT;
            &LT; /依赖和GT;
        &LT; /插件&GT;


解决方案

在最后,我的打造POM的一部分,成为这个(你可以看到它有一个焊接部分还),它是一个很长的时间,因为我用它,所以我甚至不知道,如果其确定了

 &LT;建立&GT;
    &LT; finalName&GT;的JARname&LT; / finalName&GT;
    &LT;&插件GT;
        &LT;&插件GT;
            &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
            &LT;&的artifactId GT; Maven的编译器插件&LT; / artifactId的&GT;
            &LT;&版GT; 2.4&LT; /版本&GT;
            &LT;结构&gt;
                &lt;信源&GT; 1.7 LT; /源&GT;
                &lt;目标&GT; 1.7 LT; /目标与GT;
                &LT;&编码GT; UTF-8&LT; /编码&GT;
            &LT; /结构&gt;
        &LT; /插件&GT;
        &LT;&插件GT;
            &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
            &LT;&的artifactId GT; Maven的依赖,插件&LT; / artifactId的&GT;
            &LT;&版GT; 2.3&LT; /版本&GT;
            &LT;&执行GT;
                &LT;执行与GT;
                    &LT;&ID GT;复制依赖性和LT; / ID&GT;
                    &LT;阶段&gt;包装及LT; /阶段&gt;
                    &LT;目标&GT;
                        &LT;&目标GT;复制依赖性和LT; /目标&GT;
                    &LT; /目标&GT;
                    &LT;结构&gt;
                        &LT; includeScope&GT;运行时&LT; / includeScope&GT;
                        &LT;输出目录&GT; $ {} project.build.directory / DIST / lib目录下及/输出目录&GT;
                        &LT; overWriteReleases&GT;假LT; / overWriteReleases&GT;
                        &LT; overWriteSnapshots&GT;假LT; / overWriteSnapshots&GT;
                        &LT; overWriteIfNewer&GT;真&LT; / overWriteIfNewer&GT;
                    &LT; /结构&gt;
                &LT; /执行&GT;
            &LT; /处决&GT;
        &LT; /插件&GT;
        &LT;&插件GT;
            &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
            &LT;&的artifactId GT;的maven-antrun-插件&LT; / artifactId的&GT;
            &LT;&版GT; 1.6 LT; /版本&GT;
            &LT;&执行GT;
                &LT;执行与GT;
                    &LT;阶段&gt;包装及LT; /阶段&gt;
                    &LT;结构&gt;
                        &lt;目标&GT;
                            &LT;的taskdef NAME =jfxjar类名=com.sun.javafx.tools.ant.FXJar
                                classpathref =maven.plugin.classpath/&GT;
                            &LT; jfxjar
                                destfile =$ {} project.build.directory / DIST / $ {} project.build.finalName&GT;
                                &LT;文件集DIR =$ {} project.build.directory /班/&GT;
                                &lt;应用NAME =$ {} project.namemainClass =com.google code.mzplay.principal.WeldJavaFXLauncher。/&GT;
                                &LT;资源&GT;
                                    &LT;文件集DIR =$ {} project.build.directory / DIST /包括=LIB / *罐子。/&GT;
                                &LT; /资源&GT;
                            &LT; / jfxjar&GT;
                        &LT; /目标与GT;
                    &LT; /结构&gt;
                    &LT;目标&GT;
                        &LT;&目标GT;运行&LT; /目标&GT;
                    &LT; /目标&GT;
                &LT; /执行&GT;
            &LT; /处决&GT;
            &LT;依赖和GT;
                &LT;&依赖性GT;
                    &LT;&的groupId GT; com.oracle&LT; /的groupId&GT;
                    &LT;&的artifactId GT;蚂蚁的JavaFX&LT; / artifactId的&GT;
                    &LT;&版GT; $ {javafx.version}&LT; /版本&GT;
                    &LT; Systempath下&GT; $ {java.home} /../的lib /蚁javafx.jar&LT; / Systempath下&GT;
                    &LT;&范围GT;系统和LT; /&范围GT;
                &LT; /依赖性&GT;
                &LT;&依赖性GT;
                    &LT;&的groupId GT; com.oracle&LT; /的groupId&GT;
                    &LT;&的artifactId GT;的JavaFX&LT; / artifactId的&GT;
                    &LT;&版GT; $ {javafx.version}&LT; /版本&GT;
                    &LT; Systempath下&GT; $ {java.home} /lib/jfxrt.jar</systemPath>
                    &LT;&范围GT;系统和LT; /&范围GT;
                &LT; /依赖性&GT;
            &LT; /依赖和GT;
        &LT; /插件&GT;
        &LT;&插件GT;
            &LT;的groupId方式&gt;组织codehaus.mojo&LT; /的groupId&GT;
            &LT;&的artifactId GT;声纳Maven的插件&LT; / artifactId的&GT;
            &LT;&版GT; 2.0&LT; /版本&GT;
        &LT; /插件&GT;
    &LT; /插件&GT;
    &LT; pluginManagement&GT;
        &LT;&插件GT;
            &LT;&插件GT;
                &LT;&的groupId GT; org.eclipse.m2e&LT; /的groupId&GT;
                &LT;&的artifactId GT;生命周期映射&LT; / artifactId的&GT;
                &LT;&版GT; 1.0.0&LT; /版本&GT;
                &LT;结构&gt;
                    &LT; lifecycleMappingMetadata&GT;
                        &LT; pluginExecutions&GT;
                            &LT; pluginExecution&GT;
                                &LT; pluginExecutionFilter&GT;
                                    &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
                                    &LT;&的artifactId GT; Maven的依赖,插件&LT; / artifactId的&GT;
                                    &LT; versionRange&GT; [2.0,)LT; / versionRange&GT;
                                    &LT;目标&GT;
                                        &LT;&目标GT;复制依赖性和LT; /目标&GT;
                                    &LT; /目标&GT;
                                &LT; / pluginExecutionFilter&GT;
                                &lt;作用&GT;
                                    &LT;执行/&GT;
                                &LT; /作用&gt;
                            &LT; / pluginExecution&GT;
                        &LT; / pluginExecutions&GT;
                    &LT; / lifecycleMappingMetadata&GT;
                &LT; /结构&gt;
            &LT; /插件&GT;
        &LT; /插件&GT;
    &LT; / pluginManagement&GT;
&LT; /构建&GT;

I just made a question about using javafxpackager to make JavaFX jars, you can see it here. My problem was that I couldn't include the classpath in the manifest. Well, while I was waiting for the answer, I tried maven-antrun-plugin instead. It worked nice, and I could run my application with dependencies, BUT (there is always a but) only with the dependencies OUTSIDE my final jar. So it is like that:

FinalJar.jar
lib
  |_{all dependencies here}

My manifest file is pointing to the dependencies via the JavaFX-Class-Path property. If I put the dependencies inside the jar, like I want, it doesn't find my dependencies. Any help?

EDIT: Here's the step to add the dependencies to the jar, its inside the pom.xml:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                        <target>
                            <taskdef name="jfxjar" classname="com.sun.javafx.tools.ant.FXJar"
                                classpathref="maven.plugin.classpath" />
                            <jfxjar
                                destfile="${project.build.directory}/dist/${project.build.finalName}">
                                <fileset dir="${project.build.directory}/classes" />

                                <!-- Adds the dependencies to jar -->
                                <fileset dir="${project.build.directory}/lib/" includes="*.jar" />
                                <application name="${project.name}" mainClass="com.google.code.mzplay.principal.PrincipalFX" />

                                <resources>
                                    <!-- Adds the dependencies to classpath -->
                                    <fileset dir="${project.build.directory}/lib/" includes="*.jar" />
                                </resources>
                            </jfxjar>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ant-javafx</artifactId>
                    <version>${javafx.version}</version>
                    <systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
                    <scope>system</scope>
                </dependency>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>javafx</artifactId>
                    <version>${javafx.version}</version>
                    <systemPath>${java.home}/lib/jfxrt.jar</systemPath>
                    <scope>system</scope>
                </dependency>
            </dependencies>
        </plugin>

解决方案

In the end, my "build" part of the POM became this (you can see that it has a weld part also), its been a long time since I used it, so I don't even know if its ok anymore

<build>
    <finalName>JarName</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <includeScope>runtime</includeScope>
                        <outputDirectory>${project.build.directory}/dist/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                        <target>
                            <taskdef name="jfxjar" classname="com.sun.javafx.tools.ant.FXJar"
                                classpathref="maven.plugin.classpath" />
                            <jfxjar
                                destfile="${project.build.directory}/dist/${project.build.finalName}">
                                <fileset dir="${project.build.directory}/classes" />
                                <application name="${project.name}" mainClass="com.google.code.mzplay.principal.WeldJavaFXLauncher" />
                                <resources>
                                    <fileset dir="${project.build.directory}/dist/" includes="lib/*.jar" />
                                </resources>
                            </jfxjar>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ant-javafx</artifactId>
                    <version>${javafx.version}</version>
                    <systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
                    <scope>system</scope>
                </dependency>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>javafx</artifactId>
                    <version>${javafx.version}</version>
                    <systemPath>${java.home}/lib/jfxrt.jar</systemPath>
                    <scope>system</scope>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>2.0</version>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-dependency-plugin</artifactId>
                                    <versionRange>[2.0,)</versionRange>
                                    <goals>
                                        <goal>copy-dependencies</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

这篇关于JavaFX的罐子依赖捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆