eclipse 无法在 Tomcat 和 Workspace 中找到或加载主类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15352511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:09:38  来源:igfitidea点击:

Could not find or load main class in both Tomcat and Workspace

eclipsetomcatstrutsmetadata

提问by user1287523

I have been tasked with adding some new features in a project I worked on a while back. It's been given some new features since I last worked on it, and the development environment has changed. I'm having a lot of troubles bringing my environment up to date with all the dependencies and external folders.

我的任务是在不久前参与的一个项目中添加一些新功能。自从我上次工作以来,它被赋予了一些新功能,开发环境也发生了变化。我在使我的环境更新所有依赖项和外部文件夹时遇到了很多麻烦。

After solving a host of problems, when running the Tomcat 7 Serverin EclipseI was coming across a message:

在解决了一系列问题后,在Eclipse 中运行Tomcat 7 服务器时,我遇到了一条消息:

Error: Could not find or load main class Path\To\Workspace\.metadata\plugins\cont

I tried deleted the Tomcat Serverand then recreating it with the same settings, as well as deleting my .metadatafolder from the workspace. Now I can't even get Tomcat to configure right:

我尝试删除Tomcat 服务器,然后使用相同的设置重新创建它,并.metadata从工作区中删除我的文件夹。现在我什至无法让 Tomcat 正确配置:

Error: Could not find or load main class Files\ApacheSoftwareFoundation\apache-tomcat-7.0.26.

Why isn't this working? It worked before I added a couple of needed subdirectories but I'm stumped now.

为什么这不起作用?在我添加几个需要的子目录之前它起作用了,但我现在很难过。

回答by mp31415

Just was searching for the same problem in Eclipse("Could not find or load main class").

只是在 Eclipse 中搜索同样的问题(“无法找到或加载主类”)。

It turned out in my case that there was an extra space in launch configuration arguments tab. (In Java EE perspective go to Servers, click on Tomcat server, in Overview window select 'Open launch configuration' and then go to Arguments tab). Arguments are listed as

事实证明,在我的情况下,启动配置参数选项卡中有一个额外的空间。(在 Java EE 透视图中,转到服务器,单击 Tomcat 服务器,在概览窗口中选择“打开启动配置”,然后转到参数选项卡)。参数被列为

-Dx.y.z=1 -Da.b.c=2 ...

and so on, but as the dialog itself is small and arguments go across multiple lines it's not always clear where there is a space and where there is a new line. In my case it was

等等,但是由于对话框本身很小并且参数跨越多行,因此并不总是清楚哪里有空格和哪里有新行。就我而言,它是

-Dx.y.z =1 -Da.b.c=2 ...

(there is a space before =1) which confused Tomcat and I got "Could not find or load main class" error.

(=1 之前有一个空格)这让 Tomcat 感到困惑,我收到了“无法找到或加载主类”的错误消息。

It's not necessarily your case but somebody else can come across this and find it to be the answer.

这不一定是您的情况,但其他人可以遇到此问题并找到答案。

回答by Roman C

In the .metadata folder eclipse saves it's internal configuration, so you should not affect it manually. The errors give you the clue to get that resource it's looking is not accessible what ever it exists or not. Try to find it manually to check if it exists, then try to make it accessible, fix the path, change permissions, etc. May be you have classpath issue, who knows.

在 .metadata 文件夹中 eclipse 保存它的内部配置,所以你不应该手动影响它。这些错误为您提供了获取它正在寻找的资源的线索,无论它是否存在,都无法访问。尝试手动查找以检查它是否存在,然后尝试使其可访问,修复路径,更改权限等。可能是您有类路径问题,谁知道呢。