未找到 javac1.8 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20702626/
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
javac1.8 class not found
提问by kamilz
I have installed two jdks - jdk 1.5 and jdk 1.8. I have following Ant build.xml config file :
我已经安装了两个 jdk - jdk 1.5 和 jdk 1.8。我有以下 Ant build.xml 配置文件:
<target name="compileCustomSrc">
<javac srcdir="src" destdir="build/classes" source="1.5" target="1.5" >
<classpath>
<fileset dir="C:/lib/">
<include name="*.jar" />
</fileset>
</classpath>
</javac>
</target>
Before installing jdk1.8, Ant invoked from Eclipse compiled all sources successful. But now, I have following error message:
在安装 jdk1.8 之前,从 Eclipse 调用 Ant 编译所有源成功。但是现在,我有以下错误消息:
Class not found: javac1.8
My JAVA_HOME and JRE_HOME:
我的 JAVA_HOME 和 JRE_HOME:
JAVA_HOME = C:\Program Files (x86)\Java\jdk1.5.0_16 JRE_HOME = C:\Program Files (x86)\Java\jre1.5.0_16
and set in Eclipse JRE to 1.5. Does Java 1.8 set some configs during installation?
并在 Eclipse JRE 中设置为 1.5。Java 1.8 在安装过程中是否设置了一些配置?
采纳答案by Kristian Holdhus
Class not found: javac1.8
This error is known to happen with Apache Ant versions less than 1.9.0 - which aren't compatible with Java 8. If you're using a version of Ant < 1.9.0, you should update to a 1.9.x release.
已知此错误发生在低于 1.9.0 的 Apache Ant 版本 - 与 Java 8 不兼容。如果您使用的是低于 1.9.0 的 Ant 版本,则应更新到 1.9.x 版本。
Here is the related bug report: https://issues.apache.org/bugzilla/show_bug.cgi?id=53347
这是相关的错误报告:https: //issues.apache.org/bugzilla/show_bug.cgi?id=53347
Btw, if you just want to compile with Java 8, but don't need to compile any actual Java 8 syntax, then you can pass the following argument to javac as a workaround, which would allow you to continue using an older version of Ant:
顺便说一句,如果您只想使用 Java 8 进行编译,但不需要编译任何实际的 Java 8 语法,那么您可以将以下参数传递给 javac 作为一种解决方法,这将允许您继续使用旧版本的 Ant :
-Dbuild.compiler=javac1.7
回答by Toni Toni Chopper
JAVA_HOME = C:\Program Files (x86)\Java\jdk1.5.0_16
JRE_HOME = C:\Program Files (x86)\Java\jre1.5.0_16
Your JAVA_HOME and JRE_HOME are set to the Java 1.5 installation hence 1.8 binaries (like javac
) are not found.
Set them to the Java 1.8 installation and you should be fine.
您的 JAVA_HOME 和 JRE_HOME 设置为 Java 1.5 安装,因此javac
未找到1.8 二进制文件(如)。将它们设置为 Java 1.8 安装,您应该没问题。
回答by Mike Kuenzi
I had this same issue. I had JAVA_HOME and JRE_HOME set correctly. I also had Ant > 1.9.
我有同样的问题。我正确设置了 JAVA_HOME 和 JRE_HOME。我也有 Ant > 1.9。
What I did to fix it is go into Eclipse to Window -> Preferences. Expand Ant and select Runtime. By default the Classpath tab should be selected and on the right hand side there is a button called "Ant Home". Click this button and double check it is pointed to your Ant folder.
我所做的修复它是进入 Eclipse 到 Window -> Preferences。展开 Ant 并选择运行时。默认情况下,应选择 Classpath 选项卡,并且在右侧有一个名为“Ant Home”的按钮。单击此按钮并仔细检查它是否指向您的 Ant 文件夹。
回答by Chuck Daniels
As a follow-on to Kristian Holdhus's answer (marked as correct), you can instead use the compiler
attribute on the Ant javac task. Setting compiler="modern"
should be both backward (as far back as 1.3) and forward compatible.
作为 Kristian Holdhus 答案的后续(标记为正确),您可以改为使用Ant javac taskcompiler
上的属性。设置应该向后(早至 1.3)和向前兼容。compiler="modern"
This avoids the need to set the Java System property named build.compiler
. Only in the absence of explicitly setting the compiler
attribute on the javac
task, will Ant use the value of the build.compiler
as a fallback.
这避免了设置名为 的 Java 系统属性的需要build.compiler
。只有在没有明确设置任务compiler
属性的情况下javac
,Ant 才会使用 的值build.compiler
作为后备。
回答by Neha Priya
Update Ant to 1.9.x release as Java 8 in incompatible with Ant versions less tha 1.9
将 Ant 更新到 1.9.x 版本作为 Java 8 与低于 1.9 的 Ant 版本不兼容
回答by KulDeep
I tried it with Eclise and got the same error Class not found: javac1.8
我用 Eclise 试了一下,得到了同样的错误Class not found: javac1.8
I verified the ANT version on my system
我在我的系统上验证了 ANT 版本
>ant -version
>ant -version
Apache Ant(TM) version 1.9.6 compiled on June 29 2015
2015 年 6 月 29 日编译的 Apache Ant(TM) 版本 1.9.6
When I tried to run the build.xml from the command prompt, it worked. Then I checked that in the Eclipse, it was referring to the older version of the ANT.
当我尝试从命令提示符运行 build.xml 时,它起作用了。然后我在 Eclipse 中检查,它指的是旧版本的 ANT。
I simply edited the ANT HOME path in the Eclipse and it worked from here also. :)
我只是在 Eclipse 中编辑了 ANT HOME 路径,它也从这里开始工作。:)
Below is the image from where need to edit the ANT Path in the Eclipse.
下面是需要在 Eclipse 中编辑 ANT 路径的图像。
- Right click on the build.xml file
- Run as
- External tool configurations
- Select the classpath tab
- 右键单击 build.xml 文件
- 运行方式
- 外部工具配置
- 选择类路径选项卡
Now change the ANT Home path from here.
现在从这里更改 ANT Home 路径。
回答by Brad Parks
I tried all of the other solutions, but none worked. I finally found an approach that worked for me in Eclipse:
我尝试了所有其他解决方案,但都没有奏效。我终于在 Eclipse 中找到了一种对我有用的方法:
- Right click on the ant task name, e.g. "compileCustomSrc" in the
ant
window. - Choose
Run As | External Tool Configurations
- Then on the
JRE
tab, chooseSeparate JRE: Java SE7
or whatever your java 7 is named, then hitApply
and thenRun
.
- 在
ant
窗口中右键单击 ant 任务名称,例如“compileCustomSrc” 。 - 选择
Run As | External Tool Configurations
- 然后在
JRE
选项卡上,选择Separate JRE: Java SE7
或任何您的 java 7 的名称,然后点击Apply
,然后Run
.
Your ant task will be executed, and will build correctly!
您的 ant 任务将被执行,并将正确构建!
回答by linhadiretalipe
Update Ant to 1.9.x release as Java 8 in incompatible with Ant versions less tha 1.9 or after the comand put -Dbuild.compiler=javac1.7, see the below:
将 Ant 更新到 1.9.x 版本作为 Java 8 与低于 1.9 的 Ant 版本不兼容或在命令 put -Dbuild.compiler=javac1.7 之后,请参阅以下内容:
ant release -Dbuild.compiler=javac1.7
蚂蚁发布-Dbuild.compiler=javac1.7
回答by Badal Singh
you can download and unzip ANT 1.10 on your system and try to chnage the ANT home in eclipse for your project to 1.10. It should work, Read this for more details. http://devops-badal.blogspot.com/2017/02/class-not-found-javac18-issue-while.html
您可以在您的系统上下载并解压 ANT 1.10,然后尝试将 eclipse 中的 ANT home 更改为 1.10。它应该可以工作,请阅读此内容以了解更多详细信息。http://devops-badal.blogspot.com/2017/02/class-not-found-javac18-issue-while.html
回答by SoSufi
Sometimes the issue while building the war through ANT is also related to java version miss match in build.properties files as build.XML tries to use the java version mentioned in build.compiler property
有时,通过 ANT 构建战争时的问题也与 build.properties 文件中的 java 版本不匹配有关,因为 build.XML 尝试使用 build.compiler 属性中提到的 java 版本
check whether build.compiler property is same as intended java version.
检查 build.compiler 属性是否与预期的 java 版本相同。