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

问题背景:原来做的项目想重新编译发布运行,结果在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."

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脚本成功! 在此对各位网友表示感谢!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
回答: 当出现"java could not find the main class"的错误时,一般有几种可能的原因和解决方式。其一种可能是使用高版本的JDK编译的Java类文件在较低版本的JVM上运行,导致JVM无法解释执行该类文件,从而报错"Could not find the main class.program will exit"。这种情况下,可以尝试使用相同或更低版本的JDK重新编译代码,或者升级JVM以支持高版本的Java类文件。\[1\]\[2\]另一种可能是在使用Eclipse等IDE调试代码时出现该错误,可能是由于IDE自动创建的class类和main方法出现问题。在这种情况下,可以尝试重新创建class类和main方法,或者检查项目配置和运行环境是否正确设置。\[3\] #### 引用[.reference_title] - *1* [解决运行java application时提示Could not find the main class.Program will exit.问题](https://blog.csdn.net/u014749862/article/details/50480918)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [【急救......】Could not find the main class.program will exit](https://blog.csdn.net/iteye_10770/article/details/81957980)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Eclipse提示Could not find the main class之解决](https://blog.csdn.net/weixin_42301413/article/details/115071959)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值