无法加载或找到主类,无法在命令行中工作,但不能在IDE的工作中工作 [英] Cannot load or find main class, works in command line but not in IDE's

查看:144
本文介绍了无法加载或找到主类,无法在命令行中工作,但不能在IDE的工作中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将其标记为重复项之前,请先听我讲话.

Before you mark this as a duplicate, please hear me out.

我正在尝试导入带有gradle的Java项目(功能齐全,可用于其他笔记本电脑,没有问题).

I am trying to import a java project with gradle(Fully functional, works for every other laptop with no issues).

  1. 我的项目具有100%的功能,可在其他笔记本电脑上使用

  1. My project is 100% functional, it works on every other laptop

当我的笔记本电脑重新成像为Windows 10时,这个问题就开始了

This issue started when my laptop was reimaged an set as windows 10

我已经在添加了C:\Program Files\Java\jre1.8.0_161\bin

命令行我看到的是正确的版本. (Java -version)

Command line I am seeing the correct version. (Java -version)

我右键单击我的项目配置构建路径".我确保它是我在环境变量(1.8.0_161)中提到的最新版本.

I right clicked my project "configure build path". I ensured that it is the latest version I mentioned in my environment variable (1.8.0_161).

我已经导入了我的项目,清理了构建,刷新并运行了(显示无法找到或加载主类)

I've imported my project, clean build, refreshed and ran (shows Cannot find or load main class)

在命令行中,我成功完成了gradle clean build的构建,没有错误

In the command line, I did gradle clean build builds successfully with no error

我还运行了Java应用程序java -jar app.jar我的应用程序启动并在localhost:8080上运行

I also ran my java application java -jar app.jar My applications starts up and runs on localhost:8080

我创建了一个简单的hello world测试项目,并且该项目运行没有问题.

I created a test project a simple hello world, and it is running with no issues.

所以,我的问题是什么原因导致这无法在ECLIPSE和Spring工具套件IDE中加载主类错误?

So, My question stands what is causing this cannot load main class error in ECLIPSE and in Spring tools suite IDE?

PS:我没有任何配置错误的软件包(正如我提到的项目在其他任何笔记本电脑上都能完美找到) 另外,我删除了Eclipse(.p2,.eclipse,eclipse和eclipse工作区文件夹),Java和gradle,并多次重新安装了所有

PS: I do not have any misconfigure packages(as I mentioned project works perfectly find on any other laptop) Also, I have deleted Eclipse(.p2, .eclipse, eclipse and eclipse workspace folder), Java, and gradle and reinstalled all of the multiple times.

更新

如上所述(#8),如果我运行.jar应用程序,它将可以正常工作.

As mentioned above (#8) it will work if I run the .jar application.

我也尝试通过命令提示符运行Java应用程序

I also tried running my java application thru command prompt

java C://.......myMainApp.java

java C://.......myMainApp.java

Error: Could not find or load main class com.jesse.umsswap.app.myMainApp

编辑未重复

正如我在这篇文章中提到的,Jarrod提供的两个链接无法解决我的问题.我走了那两个职位,解决方案却无法解决我的问题.

As I mentioned in this post, The two links provided by Jarrod did not resolve my issue. I have gone thru those two post and the solutions did not solve mine.

PS

您是否曾经在git中有一个可用的Java项目,但是当您克隆它时,它说的是无法加载或查找主类"?

Have you ever had a working java project in git, but when you cloned it is saying "cannot load or find main class"?

推荐答案

如果./gradlew clean build没有给出错误,则可以成功运行jar,并且Gradle包装程序正常(请参阅问题注释以获取更多信息),也许重新导入黯然失色的项目(例如Gradle项目-> buildship)可能会导致找到主班级

If ./gradlew clean build gives no errors, the resulting jar can be run successfully and your Gradle wrapper is fine (see question comments for more info), maybe reimporting the project to eclipse (as a Gradle project, -> buildship) may result in finding the main class

我的想法:您确保您的gradle构建正常运行,并且在同一workace内的其他gradle项目也正常运行.然后,下一个合乎逻辑的步骤是使用项目的新副本:重新导入它.

My thoughts: You ensured that your gradle build is working and other gradle projects within the same worksace are functional too. Then the next logical step is to work with a fresh copy of your project: Re-import it.

在关闭Eclipse之后,删除所有与Eclipse相关的文件(.settingsbin.classpath.project)以及用于启动应用程序的运行配置.确保备份或知道所有信息以重新创建它(vm args,运行配置的环境变量).

After closing eclipse delete all eclipse related files (.settings, bin, .classpath, .project) as well as the run configuration you used to start the application. Make sure you back it up or know all infos to recreate it (vm args, environment vars for your run config).

我知道这是一个侵入性的步骤,但是如果您说其他新的日食项目行得通,为什么不将您的项目也变成一个新的项目呢?

I know this is an invasive step, but if you say other fresh eclipse projects work, why not make your project a fresh one too?

这篇关于无法加载或找到主类,无法在命令行中工作,但不能在IDE的工作中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆