JAVAFx Build Failed

拥有回忆 提交于 2019-11-29 07:37:44
Ruslan Neruka

You need to setup jdk as jre in Prefereces->Java->Installed JREs, and check it as "separate jre" in External Tools Configuration->JRE in case of Eclipse

Edit: Run > External Tools > External Tool Configuration

When you new the JavaFX Project, the generated file, build.xml, maybe have wrong file path.

<?xml version="1.0" encoding="UTF-8"?>
	<project name="App2" default="do-deploy" basedir="."  xmlns:fx="javafx:com.sun.javafx.tools.ant">
	<target name="init-fx-tasks">
		<path id="fxant">
			<filelist>
				<file name="${java.home}\..\lib\ant-javafx.jar"/> <!-- wrong path -->
				<file name="${java.home}\lib\jfxrt.jar"/> <!-- wrong path -->
			</filelist>
		</path>
	
		<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
			uri="javafx:com.sun.javafx.tools.ant"
			classpathref="fxant"/>
	</target>

you have to check that where are the ant-javafx.jar and the jfxrt.jar ? For example, JDK 1.8 the two files are in the difference place, C:\Program Files\Java\jdk1.8.0_20\lib\ant-javafx.jar C:\Program Files\Java\jre1.8.0_20\lib\ext\jfxrt.jar

so now I only find the way to modify by myself...

<?xml version="1.0" encoding="UTF-8"?>
	<project name="App" default="do-deploy" basedir="."  xmlns:fx="javafx:com.sun.javafx.tools.ant">
	<target name="init-fx-tasks">
		<path id="fxant">
			<filelist>
				<file name="C:\Program Files\Java\jdk1.8.0_20\lib\ant-javafx.jar"/>
				<file name="C:\Program Files\Java\jre1.8.0_20\lib\ext\jfxrt.jar"/>
			</filelist>
		</path>
	
		<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
			uri="javafx:com.sun.javafx.tools.ant"
			classpathref="fxant"/>
	</target>

after modify the files, right click choose the Run as Ant Build!

I have a little better solution with less modification:

This fix path issue (just add ext\ to fix issue)

<path id="fxant">
    <filelist>
        <file name="${java.home}\..\lib\ant-javafx.jar"/>
        <file name="${java.home}\lib\ext\jfxrt.jar"/>
    </filelist>
</path>

Before doing this, you need to have a jdk1.8.xxx in your installed JREs list, not the jre included in the jdk package but jdk itself.
Next, in Run\External Tools\External Tools Configuration open the JRE tab and check that Execution environment is CDC-1.1/Foundation-1.1 (jdk1.8.xxx)
That's all !

I know that I'm a bit late to answer this, but so many of us are still struggling with this issue and in my case, I could not find a proper answer at any place.

In my case when I was getting the same issue, I managed to get it to work by going to Run->External Tools_>External Tools Configurations and selecting JRE Tab. I had to change the Execution environment from 1.7 to CDC-1.0/Foundation-1.0 (jdk1.7.0_25) (and CDC-1.1 also works).

Definitely a newb when it comes to ant, so not sure why the lazy install doesn't pick up the path correctly, but hopefully this will come in handy to someone else pounding their head before reaching for the excedrin.

I also got the same issue

<?xml version="1.0" encoding="UTF-8"?>
	<project name="App2" default="do-deploy" basedir="."  xmlns:fx="javafx:com.sun.javafx.tools.ant">
	<target name="init-fx-tasks">
		<path id="fxant">
			<filelist>
				<file name="${java.home}\..\lib\ant-javafx.jar"/> <!-- wrong path -->
				<file name="${java.home}\lib\jfxrt.jar"/> <!-- wrong path -->
			</filelist>
		</path>
	
		<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
			uri="javafx:com.sun.javafx.tools.ant"
			classpathref="fxant"/>
	</target>

from this removed the .. in the middle like this

--- file name="${java.home}\lib\ant-javafx.jar"---

then i got basedir error

for that i commented the basedir part and also chande the outdir path from ${basedir}

\build/deploy" outfile="addressApp" nativeBundles="exe" updatemode="background" >

        <!--<fx:platform basedir="${java.home}"/>--> <------ comment Here
        <fx:info title="addressApp" vendor="makery.ch"/>

        <fx:application refId="fxApplication"/>
        <fx:resources refid="appRes"/>
    </fx:deploy>

for the above i saw this https://github.com/reds-heig/logisim-evolution/issues/135

After that build was successful and exe file was generated in deploy folder.

Thanks StackOverflow Peeps

What I did on Windows 8.1, Java 1.8.0_192, Eclipse Photon (4.8.0) and e(fx)clipse 3.3.0.

  1. Uninstall all (incremental) Java installations (JDK, JRE)
  2. Install latest (needed) Java JDK with JRE
  3. Set default Java to JDK in Eclipse (Windows -> Preferences -> Java -> Installed JRE)
  4. Set Separate JRE to JDK in Eclipse (Run -> External Tools -> External Tools Configurations)
  5. Clean project
  6. build.fxbuild -> ant build.xml and run
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!