JAVAFx 构建失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24840414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAVAFx Build Failed
提问by user3184767
I created an app with JavaFx for windows, which is really cool. I can run it from e(fx)clipse, everthing works fine, but I can't make a jar file from the project. I can export it (Right click->Export->Runnable Jar File). However, if I run the jar on MAC OS X , in the menu bar I get "java" menuitem instead of my application name ,which i really don't like. I searched for how to hide that menuitem, or just rename it, and I found that I have to rename the "Application title*" in the build.fxbuild file. Now I can't build it.
我用 JavaFx for windows 创建了一个应用程序,这真的很酷。我可以从 e(fx)clipse 运行它,一切正常,但我无法从项目中制作 jar 文件。我可以导出它(右键单击-> 导出-> 可运行 Jar 文件)。但是,如果我在 MAC OS X 上运行 jar,在菜单栏中我会得到“java”菜单项而不是我的应用程序名称,我真的不喜欢。我搜索了如何隐藏该菜单项,或者只是重命名它,我发现我必须重命名 build.fxbuild 文件中的“应用程序标题*”。现在我无法构建它。
So this is what I really want: to remove/hide/rename the "java" menuitem in Mac OS X. If you have any experience, please share it with me. I will be really grateful :) .
所以这就是我真正想要的:在 Mac OS X 中删除/隐藏/重命名“java”菜单项。如果您有任何经验,请与我分享。我会非常感激:)。
I get the following error when I try to run the build.xml file:
当我尝试运行 build.xml 文件时出现以下错误:
[javac] Compiling 22 source files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\src\application\SajátKészlet.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 warning
[copy] Copying 12 files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\classesinit
-fx-tasks:
[taskdef] Could not load definitions from resource com/sun/javafx/tools/ant/antlib.xml. It could not be found.
do-deploy:
[copy] Copying 20 files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\dist\libs
BUILD FAILED
C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build.xml:217: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resources
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
Total time: 22 seconds
** I use: -Windows 7 64bit -jdk 8 u5 -JAVA_HOME is set -e(fx)clipse (Kepler), I downloaded the All-in-one version (for the lazy link)
** 我使用:-Windows 7 64bit -jdk 8 u5 -JAVA_HOME 设置 -e(fx)clipse (Kepler),我下载的是一体机版本(用于懒人链接)
Thanks you very much for your help!
非常感谢您的帮助!
回答by Zac
When you new the JavaFX Project, the generated file, build.xml, maybe have wrong file path.
当您新建 JavaFX 项目时,生成的文件 build.xml 可能有错误的文件路径。
<?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
您必须检查 ant-javafx.jar 和 jfxrt.jar 在哪里?比如JDK 1.8这两个文件在不同的地方,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!
修改文件后,右击选择Run as Ant Build!
回答by Linuski
I have a little better solution with less modification:
我有一个更好的解决方案,修改较少:
This fix path issue (just add ext\ to fix issue)
此修复路径问题(只需添加 ext\ 即可修复问题)
<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 !
在执行此操作之前,您需要在已安装的 JRE 列表中有一个 jdk1.8.xxx,而不是 jdk 包中包含的 jre,而是 jdk 本身。
接下来,在 Run\External Tools\External Tools Configuration 中打开 JRE 选项卡并检查执行环境是否为 CDC-1.1/Foundation-1.1 (jdk1.8.xxx) 就
这样!
回答by 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
您需要在 Prefereces->Java->Installed JREs 中将 jdk 设置为 jre,并在 Eclipse 的情况下在 External Tools Configuration->JRE 中将其检查为“separate jre”
Edit: Run > External Tools > External Tool Configuration
编辑:运行 > 外部工具 > 外部工具配置
回答by Shashwat Sharma
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).
就我而言,当我遇到同样的问题时,我设法通过转到“运行”->“外部工具”_>“外部工具配置”并选择 JRE 选项卡来使其工作。我不得不将执行环境从 1.7 更改为 CDC-1.0/Foundation-1.0 (jdk1.7.0_25)(CDC-1.1 也可以使用)。
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.
对于 ant 来说绝对是一个新手,所以不确定为什么惰性安装没有正确选择路径,但希望这对其他人在到达 excedrin 之前敲击他们的头会派上用场。
回答by theHashCode
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"---
--- 文件名="${java.home}\lib\ant-javafx.jar"---
then i got basedir error
然后我得到了 basedir 错误
for that i commented the basedir part and also chande the outdir path from ${basedir}
为此,我评论了 basedir 部分,并更改了 ${basedir} 的 outdir 路径
\build/deploy" outfile="addressApp" nativeBundles="exe" updatemode="background" >
\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
对于上述我看到了这个https://github.com/reds-heig/logisim-evolution/issues/135
After that build was successful and exe file was generated in deploy folder.
构建成功后,在部署文件夹中生成了 exe 文件。
Thanks StackOverflow Peeps
感谢 StackOverflow Peeps
回答by kayz1
What I did on Windows 8.1, Java 1.8.0_192, Eclipse Photon (4.8.0) and e(fx)clipse 3.3.0.
我在 Windows 8.1、Java 1.8.0_192、Eclipse Photon (4.8.0) 和 e(fx)clipse 3.3.0 上所做的。
- Uninstall all (incremental) Java installations (JDK, JRE)
- Install latest (needed) Java JDK with JRE
- Set default Java to JDKin Eclipse (Windows -> Preferences -> Java -> Installed JRE)
- Set Separate JREto JDKin Eclipse (Run -> External Tools -> External Tools Configurations)
- Clean project
- build.fxbuild -> ant build.xml and run
- 卸载所有(增量)Java 安装(JDK、JRE)
- 使用 JRE安装最新的(需要的)Java JDK
- 在 Eclipse 中将默认 Java 设置为JDK(Windows -> Preferences -> Java -> Installed JRE)
- 在 Eclipse 中将单独的 JRE设置为JDK(运行 -> 外部工具 -> 外部工具配置)
- 清洁工程
- build.fxbuild -> ant build.xml 并运行