Java 无法找到或加载主类 org.apache.tools.ant.launch.launcher

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

Could not find or load main class org.apache.tools.ant.launch.launcher

javaapacheant

提问by jason

I am using Windows 7. I have downloaded Apache ant to C:/Program Files

我使用的是 Windows 7。我已经将 Apache ant 下载到 C:/Program Files

  1. Here is my ANT_HOME: C:\Program Files\apache-ant-1.9.4
  2. Here is my JAVA_HOME: C:\Program Files\Java\jdk1.7.0_25
  3. Here is my part of path: C:\Program Files\Java\jdk1.7.0_25\jre\bin;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files\apache-ant-1.9.4\bin
  1. 这是我的 ANT_HOME: C:\Program Files\apache-ant-1.9.4
  2. 这是我的 JAVA_HOME: C:\Program Files\Java\jdk1.7.0_25
  3. 这是我的部分路径: C:\Program Files\Java\jdk1.7.0_25\jre\bin;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files\apache-ant-1.9.4\bin

I also checked that ant-launcher.jaris under /libdirectory, and I get the error in the title.

我还检查了ant-launcher.jar它在/lib目录下,我在标题中看到了错误。

How can I fix it? Thanks.

我该如何解决?谢谢。

采纳答案by user2833557

For some weird reason, ant does not work if your ANT_HOME has spaces in it. Put it in a path without any spaces, it should work. Also try putting your java in a path without spaces.

出于某种奇怪的原因,如果您的 ANT_HOME 中有空格,则 ant 将无法工作。把它放在没有任何空格的路径中,它应该可以工作。还可以尝试将您的 java 放在没有空格的路径中。

回答by Sumit Kumar Saha

There is another workaround for you, if you don't want to change the ant path. Just change the env variable path with C:\Progra~1\apache.... and if your files are placed in program files(x86) then instead of Progra~1 , write Progra~2.

如果您不想更改蚂蚁路径,还有另一种解决方法。只需使用 C:\Progra~1\apache.... 更改 env 变量路径,如果您的文件放置在程序文件(x86)中,那么请编写 Progra~2 而不是 Progra~1 。

But it's advisable to keep them in a path, with no space in the folder's name

但建议将它们保存在路径中,文件夹名称中没有空格