"Could not find the main class. Program will exit."
February 20, 2006 at 1:28 pm · Filed underGeneral
I just installed the latest availableEclipseversion (3.2 milestone 5) and couldn't run my ANT builds anymore. The error I got in the alert box was "Could not find the main class. Program will exit".
The problem was that the ANT_HOME variable was still pointing to the previous Eclipse folder and the solution was simply to change the path. This can be done through Window->Preferences->Ant->Runtime. Once there, click the "Ant home…" button in the "Classpath" tab and browse to the ANT plugin folder in your Eclipse installation. Now hit the OK button and try to run the build file again. Everything should work again.
Oh and by the way, I had a really good laugh with the "Run Garbage Collector" button
这种情况通常是发生在换了另一份 Eclipse 拷贝之后。之前一般都能正常在 Eclipse 中执行 Ant 脚本,删除了原来的 Eclipse 之后换了另一个拷贝或者是新版本,在其中执行 Ant 脚本时弹出窗口出现以下错误:
--------------------------- Java Virtual Machine Launcher --------------------------- Could not find the main class. Program will exit. --------------------------- 确定 ---------------------------
这种错误对用过 Java 的人来说还是很明白,找不到 Ant 的主类吗。不过说实话也困扰过我一段时间,也没去深究。说开了,症结就是 Eclipse 中的 ANT_HOME 指向不对。
解决办法:Eclipse 中进入 Window->Preferences->Ant->Runtime,在Classpath 标签页,看到 Ant Home Entries 指向的目录不对了(它仍然指向你上回的目录,而这个目录应该不存在了),你要做的就是改变 Ant Home 指向正确的目录,点 Ant Home 按钮,选择 Ant Home 目录,比如我用的 Eclipse 是 3.3.1 的,Ant Home 是 Eclipse 的插件目录下的 org.apache.ant_1.7.0.v200706080842。