Ant 在 Eclipse Kepler 中不起作用(Java 虚拟机启动器 - 发生了 Java 异常)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18453100/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:44:00  来源:igfitidea点击:

Ant not working in Eclipse Kepler (Java Virtual Machine Launcher - A Java Exception has occured)

javaeclipseanteclipse-kepler

提问by Pink Jazz

I recently upgraded to Eclipse Kepler, and am having issues with Ant. I am getting the Java Virtual Machine Launcher - A Java Exception has occurred error no matter which target I choose in my build files.

我最近升级到 Eclipse Kepler,但遇到了 Ant 问题。我正在获取 Java 虚拟机启动器 - 无论我在构建文件中选择哪个目标,都发生了 Java 异常错误。

I tried reinstalling my JDK, and I still get the error. I am running the 7u25 version of the JDK. I have my JAVA_HOME environment variable set to C:\Progra~1\Java\jdk1.7.0_25, so I don't think this is the problem. What else could be causing the problem?

我尝试重新安装 JDK,但仍然出现错误。我正在运行 JDK 的 7u25 版本。我的 JAVA_HOME 环境变量设置为C:\Progra~1\Java\jdk1.7.0_25,所以我不认为这是问题所在。还有什么可能导致问题?

EDIT: I also tested ant in the command line and it works just fine. Is this a bug in Kepler?

编辑:我还在命令行中测试了 ant,它工作得很好。这是开普勒的错误吗?

EDIT 2: Here is the log of the errors:

编辑 2:这是错误的日志:

org.eclipse.core.runtime.CoreException: Could not find one or more classes: "org.apache.tools.ant.BuildLogger". Please check the Ant classpath.
at org.eclipse.ant.core.AntRunner.problemLoadingClass(AntRunner.java:467)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:380)
at org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate.runInSameVM(AntLaunchDelegate.java:307)
at org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate.launch(AntLaunchDelegate.java:260)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:858)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:707)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:700)
at org.eclipse.core.externaltools.internal.model.ExternalToolBuilder.launchBuild(ExternalToolBuilder.java:181)
at org.eclipse.core.externaltools.internal.model.ExternalToolBuilder.doBuildBasedOnScope(ExternalToolBuilder.java:169)
at org.eclipse.core.externaltools.internal.model.ExternalToolBuilder.build(ExternalToolBuilder.java:88)
at org.eclipse.core.internal.events.BuildManager.run(BuildManager.java:726)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:514)
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:423)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:830)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:707)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1018)
at org.eclipse.debug.internal.ui.DebugUIPlugin.run(DebugUIPlugin.java:1222)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Caused by: java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildLogger
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:324)
... 24 more

Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.BuildLogger
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at org.eclipse.ant.internal.core.AntClassLoader.findClass(AntClassLoader.java:54)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 29 more

回答by dispake

Possible that Eclipse does not have the correct JAR defined. Did you try to add the tools.jar needed for Ant?

可能是 Eclipse 没有定义正确的 JAR。您是否尝试添加 Ant 所需的 tools.jar?

Preferences > Ant > Runtime

首选项 > Ant > 运行时

enter image description here

在此处输入图片说明

回答by Omid

I had the same problem and it kept me a while to figure out what the solution is. I followed all the suggestion on this page and similar pages; nothing helpt! I uninstalled and installed jdk, eclipse, reset my project, I forced Eclipse clear it's parameters, ...; no success.

我遇到了同样的问题,这让我花了一段时间才弄清楚解决方案是什么。我遵循了此页面和类似页面上的所有建议;没有任何帮助!我卸载并安装了 jdk、eclipse,重置了我的项目,我强制 Eclipse 清除了它的参数,...;没有成功。

What finally fixed my problem was deleting the .metadata directory in the workspace folder. I don't know what eclipse keeps in there, but deleting the .metadata direcotry caused Eclipse reinitiate every setting. I did have to reimport my project structure. It works again like a charm. No vague 'There is an exception occured' error message.

最终解决我的问题的是删除工作区文件夹中的 .metadata 目录。我不知道 eclipse 中保留了什么,但是删除 .metadata 目录会导致 Eclipse 重新启动每个设置。我确实必须重新导入我的项目结构。它再次像魅力一样工作。没有模糊的“发生异常”错误消息。

回答by immobiluser

In my case :

就我而言:

  • no log in eclipse, just message : Java Virtual Machine Launcher : A Java Exception has occured.
  • 没有登录 Eclipse,只是消息:Java 虚拟机启动器:发生 Java 异常。

Due to the re-use of a old workspace with a different Eclipse version, i solved by replacing all jar dependency in Ant->Runtime->Classpath->Ant Home Entries (Default) by reals and existing jar (from my eclipse-jee-kepler-SR1-win32-x86_64\eclipse\plugins\org.apache.ant_1.8.4.v201303080030\lib)

由于重新使用具有不同 Eclipse 版本的旧工作区,我通过将 Ant->Runtime->Classpath->Ant Home Entries (Default) 中的所有 jar 依赖项替换为 reals 和现有 jar(来自我的 eclipse-jee -kepler-SR1-win32-x86_64\eclipse\plugins\org.apache.ant_1.8.4.v201303080030\lib)

It's explain on : https://bugs.eclipse.org/bugs/show_bug.cgi?id=102463#c41

它的解释:https: //bugs.eclipse.org/bugs/show_bug.cgi?id=102463#c41

回答by theAspirant

I had the same error; switched workspace from Eclipse Indigo to Eclipse Kepler. I was able to resolve it by resetting the Ant_Home value. It was originally pointing to the correct folder, but I just reset it to the same folder and clicked on 'Apply'. Works fine now. Hope this helps.

我有同样的错误;将工作区从 Eclipse Indigo 切换到 Eclipse Kepler。我能够通过重置 Ant_Home 值来解决它。它最初指向正确的文件夹,但我只是将其重置为同一文件夹并单击“应用”。现在工作正常。希望这可以帮助。

回答by Omar Faroque Anik

For me, I just delete the metadata folder and start eclipse with import all of your library project. Check your ant class path and add this jar again. Thanks

对我来说,我只是删除元数据文件夹并通过导入所有库项目启动 eclipse。检查您的 ant 类路径并再次添加此 jar。谢谢

回答by Sankalp

This is most likely due to difference in Ant version being used by eclipse. Please update Ant_Home in eclipse . Window --> Preferences --> Ant --> Runtime --> Classpath -->Click Ant Home.. and try to locate the latest version of Ant directory location. This works for me :)

这很可能是由于 eclipse 使用的 Ant 版本不同。请在 eclipse 中更新 Ant_Home 。Window --> Preferences --> Ant --> Runtime --> Classpath -->点击 Ant Home.. 并尝试定位到最新版本的 Ant 目录位置。这对我有用:)

回答by shonky linux user

In my case ant home was pointing to a symbolic link (to a real ant installation). Eclipse didn't like that. Updating to the actual installation folder solved the issue.

在我的例子中,ant home 指向一个符号链接(指向一个真正的 ant 安装)。Eclipse 不喜欢那样。更新到实际安装文件夹解决了这个问题。

回答by jhertz

For me the problem were the JDK I were trying to use. The project I wanted to build was setup to use the 1.6 JDK. I got the same error as the questioner, but when I changed to Java 8 the build worked fine. So I am assuming that the ANT version that comes with newer versions Eclipse does not work with older JDKs.

对我来说,问题是我试图使用的 JDK。我想构建的项目设置为使用 1.6 JDK。我遇到了与提问者相同的错误,但是当我更改为 Java 8 时,构建工作正常。因此,我假设较新版本 Eclipse 附带的 ANT 版本不适用于较旧的 JDK。

enter image description here

在此处输入图片说明

回答by Sireesh Yarlagadda

IDE like (Eclipse-Oxygen) will have default ant versions. If your ant build XML is not compatible with higher version of ANT.

像 (Eclipse-Oxygen) 这样的 IDE 将具有默认的 ant 版本。如果您的 ant 构建 XML 与更高版本的 ANT 不兼容。

Lower/Higher the ANT version to the suitable one. JDK is not compatible with all ANT Builds. For Instance, ANT 1.9.2 is the last version to support JAVA 7.

将 ANT 版本降低/提高到合适的版本。JDK 与所有 ANT 版本都不兼容。例如,ANT 1.9.2 是支持 JAVA 7 的最后一个版本。

So we need to match the JDK version and ANT version's respectively. Override the IDE default version using Preferences -> ANT -> Runtime -> Click on Ant Home (and choose the new version of ANT Home there, that will override the Ant Home Entries)

所以我们需要分别匹配JDK版本和ANT版本。使用 Preferences -> ANT -> Runtime -> 单击 Ant Home 覆盖 IDE 默认版本(并在那里选择新版本的 ANT Home,这将覆盖 Ant Home 条目)

回答by TT.

I had this problem recently (then a colleague) in Eclipse when running an ANT script from the UI interface (context menu, Run Asor Debug As).

我最近(当时是同事)在 Eclipse 中从 UI 界面(上下文菜单Run AsDebug As)运行 ANT 脚本时遇到了这个问题。

Due to some reason, the Runtime JRE for the ANT script (or for ANT itself, unclear at this point) got changed. This Runtime JRE can be changed from the context menu for the ANT script, External Tools Configurations...:

由于某种原因,ANT 脚本(或 ANT 本身,目前尚不清楚)的运行时 JRE 已更改。可以从 ANT 脚本的上下文菜单中更改此运行时 JRE External Tools Configurations...

Context Menu - Run As - External Tools Configuration

上下文菜单 - 运行方式 - 外部工具配置

Then move on to the JRE tab on the right side:

然后转到右侧的 JRE 选项卡:

External Tools Configuration - Runtime JRE

外部工具配置 - 运行时 JRE

My colleague had the Separate JREsetting wrong, changed it to the proper JRE setting (JDK 1.8_XXX in his case). This was after a merge, where apparantly some incorrect settings were merged into a branch (or so we think).

我的同事Separate JRE设置错误,将其更改为正确的 JRE 设置(在他的情况下为 JDK 1.8_XXX)。这是在合并之后,显然一些不正确的设置被合并到一个分支中(或者我们认为是这样)。

In my case, I think I had this set as Run in the same JRE as the workspacewhich was wrong. I also set this to Separate JRE, chose the proper 1.8 JDK and that fixed the issue. This was after an upgrade of the Eclipse version (as I recall).

就我而言,我认为我有这个设置Run in the same JRE as the workspace是错误的。我还将其设置为Separate JRE,选择了正确的 1.8 JDK 并解决了该问题。这是在 Eclipse 版本升级之后(我记得)。