`
yucang52555
  • 浏览: 69413 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

(转载)myeclipse出现Could not find the main class原因分析

 
阅读更多
昨天晚上像往常一样打开myeclipse,随便运行一个类(run as java application),居然弹出Could not find the main class.Program will exit.报错如下:
Caused by: java.lang.ClassNotFoundException: localhostjdk
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

按照以往的经验,做如下检查:

编译环境检查 window->preferences->installed JREs
编译级别检查 右击工程名->properties->java compiler
编译路径检查 右击工程名->build path->coufiguration build path
执行clean     project->clean
按照上面的检查后发现,没有任何问题,并且在同一个workspace中的工程里的class都能正常运行。
看来跟该工程的相关设置文件有关了(例如.classpath,.mymetadata,.mymetadata),于是乎
将工程拷贝一份重新建立了一个新工程,并进行了比对,果然发现了问题:

.classpath文件跟新建的工程中的不同(可参考http://leagion.iteye.com/blog/477849),但
杯具的是,我将新建的工程中的.classpath覆盖原工程中的.classpath后,问题依旧,真是无奈,最后
查看了run configurations的java application中发现有很多原来运行的类,全部删除,重新运行居然
好了,神马就是浮云啊!

总结:遇到此类问题,请首先查看运行环境的配置(如jre,classpath,complie level等),执行clean操作,
删除之前的run configurations中的java application中的记录,实在不行就只好重新建立工程了。毕竟像
myeclipse(eclipse)这种工具总会出现这样那样的问题,有些确实很难找到根源,只能绕道解决了。
分享到:
评论

相关推荐

    Could not find the main class

    "Could not find the main class" 是一个常见的错误提示,出现于 MyEclipse 8.5 中使用外带的 Tomcat 时,因 JDK 版本问题所引起。下面将详细解释该错误的解决方案。 错误原因 在 MyEclipse 8.5 中,当我们使用...

    myEclipse工程打包及exe文件制作

    如果你遇到"could not find main class"的错误,很可能是因为manifest文件中的Main-Class配置不正确。 在完成以上步骤后,通过组合使用myEclipse的jar打包、Launch4j的exe制作和ResHacker的资源编辑,你就能成功地...

    Myeclipse中配置 jboss 图解

    - 路径中存在空格会导致MyEclipse在启动服务器时报错:“Could not find the main class”。 - **其他注意事项**: - 在配置过程中确保所有步骤都正确执行。 - 检查JBoss版本与MyEclipse版本兼容性。 - 如果...

    MyEclipse报错说明

    3. **Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update** Hibernate在执行数据库批处理更新时出现SQL语法错误,可能是由于数据库表不存在或结构不符...

    在eclipse中配置 jboss 图解

    因为这样的路径会导致MyEclipse在启动服务器时出现"Could not find the main class"错误。如果遇到此类问题,应立即移动JBoss到一个不含空格的目录。 5. **其他注意事项** - 配置过程中,确保MyEclipse和JBoss的...

Global site tag (gtag.js) - Google Analytics