问题描述
我正在开发在Eclipse JavaFX应用程序。该应用程序有外部库,像log4j的和其他人,并从Eclipse的完美运行。我试着从Eclipse作为通过Eclipse运行的JAR内置功能部署它,它运行良好某些计算机上,而在其他它会给我一个不起眼的未定义的链接错误。周围挖后似乎JavaFX的需要或者通过Ant脚本或通过的javafxpackager
应用程序使用特殊包装。
有关我的生活,我似乎无法或者通过这些方法来部署一个可运行罐子。无论是尝试这些方法,我得到一个异常。事情我已经试过:
-
通过构建一个Ant脚本的JavaFX应用程序,下面是构建脚本的相关部分的片段
<路径ID =类路径>
<文件集DIR =$ {} lib.dir包括=** / *罐子。/>
<文件集DIR =$ {} javafx.sdk.path / JRE / lib目录包括=jfxrt.jar/>
< /路径><目标名称=编译取决于=干净>
<回声>编译源< /回声>
< MKDIR DIR =$ {} classes.dir/>
<! - 在杂项文件到类目录复制 - >
<副本todir =$ {} classes.dir /捆绑>
<文件集DIR =$ {}对于src.dir /捆绑/>
< /复制>
<副本todir =$ {} classes.dir / CSS>
<文件集DIR =$ {}对于src.dir / CSS/>
< /复制>
<副本todir =$ {} classes.dir / IMG>
<文件集DIR =$ {}对于src.dir / IMG/>
< /复制>
<副本todir =$ {} classes.dir /视图>
<文件集DIR =$ {}对于src.dir /视图/>
< /复制> <副本todir =$ {} classes.dir /捆绑>
<文件集DIR =$ {}对于src.dir /捆绑/>
< /复制> <复制文件=$ {}对于src.dir /log4j2.xmltodir =$ {} classes.dir/> < javac的目标=1.7SRCDIR =$ {}对于src.dirDESTDIR =上的&GT$ {} classes.dirclasspathref =类路径调试=;
< / javac的>
< /目标与GT;<目标名称=罐子依赖=编译>
<回声>创建主jar文件< /回声>
< MKDIR DIR =$ {} distro.dir/>
< FX:罐子destfile =$ {} distro.dir /main.jar详细=真>
<外汇:JavaFX的平台=2.1+J2SE =7.0/>
< FX:应用mainClass =$ {} main.class/> <! - 什么要加入到结果的jar文件?
一切都在构建树 - >
<文件集DIR =$ {} classes.dir/> <! - 定义需要哪些辅助的资源
这些文件将进入清单文件,
那里的类路径定义 - >
< FX:资源>
< FX:文件集DIR =$ {} distro.dir包括=main.jar文件/>
< FX:文件集DIR =。包括=$ {lib.dir} / **TYPE =罐子/>
< FX:文件集DIR =。包括= /&gt的帮助。
< / FX:资源> <! - 做一些更新清单文件 - >
<&舱单GT;
<属性名=实施厂商价值=$ {} app.vendor/>
<属性名=实施-标题值=$ {} app.name/>
<属性名=类路径值=$ {} lib.dir/>
<属性名=实施-版本值=1.0/>
< /清单>
< / FX:罐>
< /目标与GT;
编译/生成通过ant脚本的罐子,我得到一个窗口弹出在控制台半秒和应用程序启动方式异常,不具有堆栈跟踪。我试过捉迷藏与的java -XX:-OmitStackTraceInFastThrow
标志,但它仍然不会给我一个堆栈跟踪。
-
到
的javafxpackager
运行提供了以下错误:RenderJob.run:内部异常
java.lang.UnsatisfiedLinkError中:com.sun.prism.d3d.D3DContext.nSetBlendEnabled(JZ
Z)我
在com.sun.prism.d3d.D3DContext.nSetBlendEnabled(本机方法)
在com.sun.prism.d3d.D3DContext.initState(D3DContext.java:84)
在com.sun.prism.d3d.D3DResourceFactory。(D3DResourceFactory.java:5
7)
在com.sun.prism.d3d.D3DPipeline.createResourceFactory(D3DPipeline.java:
147)
在com.sun.prism.d3d.D3DPipeline.getD3DResourceFactory(D3DPipeline.java:
153)
在com.sun.prism.d3d.D3DPipeline.findDefaultResourceFactory(D3DPipeline。
Java的:179)
在com.sun.prism.d3d.D3DPipeline.getDefaultResourceFactory(D3DPipeline.j
AVA:201)
在com.sun.prism.GraphicsPipeline.getDefaultResourceFactory(GraphicsPipe
line.java:97)
在com.sun.javafx.tk.quantum.QuantumRenderer $ 3.run(QuantumRenderer.java:
143)
在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:47
1)
在java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
在com.sun.prism.render.RenderJob.run(RenderJob.java:37)
在java.util.concurrent.ThreadPoolExecutor.runWorker(的ThreadPoolExecutor。
Java的:1145)
在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(的ThreadPoolExecutor
的.java:615)
在com.sun.javafx.tk.quantum.QuantumRenderer $ PipelineRunnable.run(Quantu
mRenderer.java:98)
在java.lang.Thread.run(Thread.java:724)
您可以使用的javafxpackager
部署应用程序。如果部署的自包含应用程序,Java运行时环境将与您的应用程序捆绑在一起,它将Java的正确版本是否安装或没有任何一台机器上运行。
(你应该有的javafxpackager
中的bin文件夹下你的JDK目录。的)
-
查找您编译的文件(
的.class
)的Eclipse工作区文件夹。他们应该在bin目录下。 -
创建一个
createjar
文件夹,并在里面创建一个类
和出
文件夹中。所有的.class文件复制在类
文件夹中。还包括在类文件夹中的应用程序所需的所有jar。 -
现在在命令行上走
createjar
目录中并运行此命令:C:\\路径\\为\\ jdk的\\ jdk1.7.0_25 \\ BIN \\ javafxpackager.exe-createjar -appClass package.MainClass -srcdir类-outdir出-OUTFILE NameOfYourJar -classpath-v
这应该创建在运行的JAR出来
目录即可。你会需要它的下一个步骤。
-
现在创建旁边的
createjar
文件夹部署
文件夹中。 -
在
部署
文件夹作出其他目录DIST
和包
。 -
在
DIST
文件夹从上面复制你刚创建的罐子加上所有的依赖/ ressources它将需要。
返回在命令行上(如果你曾经离开它),并走在了部署
目录。从那里运行以下命令:
C:\\路径\\为\\ jdk的\\ jdk1.7.0_25 \\ BIN \\ javafxpackager.exe-deploy -native -outdir包-OUTFILE NameOfYourApp -srcdir DIST -srcfiles NameOfYourJar。罐子-appClass package.MainClass -name你的姓名申请-title应用程序标题
一旦完成它应该创建所有你需要部署应用程序,包括原 .exe文件
文件在Windows平台上运行。这是自包含的应用程序!为了能够运行它,你需要进入捆绑\\ NameOfYourApp \\ APP
并粘贴在这里所有的依赖关系/的ressource您的应用程序的需求。
在上YourApp.exe最后,双击它应该在机器上运行,即使没有Java安装。
I'm developing a JavaFX application in Eclipse. The app has external libraries, like log4j and others and runs perfectly from Eclipse. I've tried deploying it from Eclipse as a Runnable jar through the Eclipse built-in feature, and it runs well on some computers, while on others it would give me an obscure Undefined Link error. After digging around it seems JavaFX needs to be specially packaged either through an ANT script or through the javafxpackager
application.
For the life of me I can't seem to deploy a runnable jar through either of those methods. Trying either of those methods, I get an Exception. Things I've tried:
Build the JavaFX application through an ANT script, below is a snippet of the relevant parts of the build script
<path id="classpath"> <fileset dir="${lib.dir}" includes="**/*.jar"/> <fileset dir="${javafx.sdk.path}/jre/lib" includes="jfxrt.jar"/> </path> <target name="compile" depends="clean"> <echo>Compiling the source</echo> <mkdir dir="${classes.dir}"/> <!-- Copy over the misc files into the classes dir --> <copy todir="${classes.dir}/bundles"> <fileset dir="${src.dir}/bundles"/> </copy> <copy todir="${classes.dir}/css"> <fileset dir="${src.dir}/css"/> </copy> <copy todir="${classes.dir}/img"> <fileset dir="${src.dir}/img"/> </copy> <copy todir="${classes.dir}/views"> <fileset dir="${src.dir}/views"/> </copy> <copy todir="${classes.dir}/bundles"> <fileset dir="${src.dir}/bundles"/> </copy> <copy file="${src.dir}/log4j2.xml" todir="${classes.dir}"/> <javac target="1.7" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" debug="on"> </javac> </target> <target name="jar" depends="compile"> <echo>Creating the main jar file</echo> <mkdir dir="${distro.dir}" /> <fx:jar destfile="${distro.dir}/main.jar" verbose="true"> <fx:platform javafx="2.1+" j2se="7.0"/> <fx:application mainClass="${main.class}"/> <!-- What to include into result jar file? Everything in the build tree--> <fileset dir="${classes.dir}"/> <!-- Define what auxilary resources are needed These files will go into the manifest file, where the classpath is defined --> <fx:resources> <fx:fileset dir="${distro.dir}" includes="main.jar"/> <fx:fileset dir="." includes="${lib.dir}/**" type="jar"/> <fx:fileset dir="." includes="."/> </fx:resources> <!-- Make some updates to the Manifest file --> <manifest> <attribute name="Implementation-Vendor" value="${app.vendor}"/> <attribute name="Implementation-Title" value="${app.name}"/> <attribute name="Class-Path" value="${lib.dir}"/> <attribute name="Implementation-Version" value="1.0"/> </manifest> </fx:jar> </target>
Compiling/generating the jar through the ant script, I get a window pop up for half a second and "Exception in Application start method" in the console, with no stack trace. I've tried runnning java with the -XX:-OmitStackTraceInFastThrow
flag, but it still won't give me a stack trace.
Running through
javafxpackager
gives the following error:RenderJob.run: internal exceptionjava.lang.UnsatisfiedLinkError: com.sun.prism.d3d.D3DContext.nSetBlendEnabled(JZZ)I at com.sun.prism.d3d.D3DContext.nSetBlendEnabled(Native Method) at com.sun.prism.d3d.D3DContext.initState(D3DContext.java:84) at com.sun.prism.d3d.D3DResourceFactory.(D3DResourceFactory.java:57) at com.sun.prism.d3d.D3DPipeline.createResourceFactory(D3DPipeline.java:147) at com.sun.prism.d3d.D3DPipeline.getD3DResourceFactory(D3DPipeline.java:153) at com.sun.prism.d3d.D3DPipeline.findDefaultResourceFactory(D3DPipeline.java:179) at com.sun.prism.d3d.D3DPipeline.getDefaultResourceFactory(D3DPipeline.java:201) at com.sun.prism.GraphicsPipeline.getDefaultResourceFactory(GraphicsPipeline.java:97) at com.sun.javafx.tk.quantum.QuantumRenderer$3.run(QuantumRenderer.java:143) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at com.sun.prism.render.RenderJob.run(RenderJob.java:37) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:98) at java.lang.Thread.run(Thread.java:724)
You can deploy your application using javafxpackager
. If you deploy a self contained application, the Java Runtime Environment will be bundled with your application and it will run on any machine whether the right version of Java is installed or not.(You should have javafxpackager
in your jdk directory under the bin folder.)
Look for your compiled files (
.class
) in your eclipse workspace folder. They should be in the bin directory.Create a
createjar
folder and inside it create aclasses
and aout
folder. Copy all of your .class files in theclasses
folder. Also include in the classes folder all jar needed by your application.Now on the command line go inside the
createjar
directory and run this command :"C:\path\to\jdk\jdk1.7.0_25\bin\javafxpackager.exe" -createjar -appclass package.MainClass -srcdir classes -outdir out -outfile NameOfYourJar -classpath "" -v
This should create a runnable jar in the out
directory. You will need it for the next step.
Now create a
deploy
folder alongside thecreatejar
folder.Inside the
deploy
folder make to other directoriesdist
andpackages
.In the
dist
folder copy your freshly created jar from above plus all the dependencies/ressources it will need.
Go back on the command line (if you ever left it) and go in the deploy
directory. Run the following command from there :
"C:\path\to\jdk\jdk1.7.0_25\bin\javafxpackager.exe" -deploy -native -outdir packages -outfile NameOfYourApp -srcdir dist -srcfiles NameOfYourJar.jar -appclass package.MainClass -name "Name of You Application" -title "Title of your application"
Once it is done it should have created all you need to deploy your app including native .exe
file to run on Windows platform. This is the self contained application ! To be able to run it you need to go into bundles\NameOfYourApp\app
and paste here all dependencies/ressource your app needs.
At last, double click on YourApp.exe and it should run even on machines without Java installed.
这篇关于无法在JAR部署的JavaFX应用程序了与外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!