您的位置:首页 > 编程语言 > Java开发

Eclipse中执行Ant脚本出现Could not find the main class的问题及解

2008-04-17 12:00 633 查看
问题背景:原来做的项目想重新编译发布运行,结果在Eclipse下执行初始化Ant脚本时系统报"Could not find the main class. Program will exit."

解决方式:首先在网上搜索了一下问题解决方案,

1)myeclipse中出現"Could not find the main class. Program will exit."

2007-11-18 04:16 P.M.
出現這個,原來是選錯了東西,windows--preferences--java--installed jres--這里我選擇了jdk,應該是選擇jre的!

不知道對不對,我的是選擇這個就行了,我網上也找過了,找到了下面這個原文,不過我用了,好像沒有用!

"Could not find the main class. Program will exit."

February 20, 2006 at 1:28 pm · Filed under General

I just installed the latest available Eclipseversion (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

http://www.herrodius.com/blog/?p=42

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1046337

结果:按方案执行,现在用的是Eclipse3.3.2,将JRES改为原来开发时用的1.4,依然未成功!

2)"Eclipse中执行Ant出现Could not find the main class的问题及解 "

=====================================================================

这种情况通常是发生在换了另一份 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。

现在可以再次在 Eclipse 中执行你的 Ant 脚本,是不是能正常运行了啊!

============================================================================

结果:按照上述操作步骤执行,依然未成功。(解决思路是正确的)

最终解决:解决方法 与上述过程无异,Eclipse 中进入 Window->Preferences->Ant->Runtime,选择ant的Jar包在自己的项目中两个ant.jar和ant-!launcher.jar,点击确定后,重新执行ant的XML脚本成功! 在此对各位网友表示感谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐