Java 将动态 Web 项目导入 Eclipse

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2972447/
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-08-13 15:03:26  来源:igfitidea点击:

Importing Dynamic Web Project into Eclipse

javaeclipse

提问by Bob

I've been working on a dynamic web project in Eclipse. I have recently reInstalled my OS and I use a clean eclipse. I can import my web project, but when I try to lunch (run on server) I always get this message:

我一直在 Eclipse 中开发一个动态 Web 项目。我最近重新安装了我的操作系统并且我使用了一个干净的 Eclipse。我可以导入我的 Web 项目,但是当我尝试吃午饭(在服务器上运行)时,我总是收到以下消息:

"The selection cannot be run on any server"

I installed the eclipse's tomcat plugin, and it works fine. I set the tomcat library too. (window/preferences/tomcat).

我安装了eclipse的tomcat插件,运行正常。我也设置了 tomcat 库。(窗口/首选项/ tomcat)。

What's the problem with it?

它有什么问题?

采纳答案by Ross

If I understand you correctly you have imported a previously working web project into a clean install of Eclipse (and OS) and you are tying to run the project on Tomcat. There could be a number of reasons why it isn't working, here are some things to consider in troubleshooting:

如果我对您的理解正确,您已经将以前工作的 Web 项目导入到 Eclipse(和操作系统)的全新安装中,并且您正准备在 Tomcat 上运行该项目。它不工作的原因可能有很多,以下是故障排除时需要考虑的一些事项:

  1. First thing to validate is whether or not Tomcat has been installed correctly and is running without errors. You say you installed a Tomcat plugin for Eclipse. I didn't know there was one. I usually install Tomcat separately and then configure Tomcat settings in Eclipse. Or did you install Tomcat via the Servers view? Windows -> View -> Other -> Server -> Servers, right click in Server view and go New -> Server. Select Apache and then Tomcat?
  2. Can you start and stop Tomcat within Eclipse? If so can you open a browser and navigate to http://localhost:8080- a Tomcat console should display. Check the logs there shouldn't be any errors.
  3. You should be able to right click on your web project and say run on server and select Tomcat. Alternatively in the Server view right click on the Tomcat server and select Add and Remove.
  4. If the 3rd step didn't work it is possible that the imported project has errors. Could be referencing Libraries that don't exist or paths that are invalid. Open the problems view and see if there are any compile errors. Open the errors view and see if there are any eclipse errors. Right click the project -> Build path -> Configure build path. Examine the reference libraries and see if there are any errors or warnings.
  5. If you the above all works and you have still not made any progress try creating a simple dynamic web application from scratch and run that on the server.
  1. 首先要验证的是 Tomcat 是否已正确安装并且运行时没有错误。你说你为 Eclipse 安装了一个 Tomcat 插件。我不知道有一个。我一般是单独安装Tomcat,然后在Eclipse中配置Tomcat设置。或者您是否通过服务器视图安装了 Tomcat?Windows -> 查看 -> 其他 -> 服务器 -> 服务器,在服务器视图中右键单击并转到新建 -> 服务器。选择Apache,然后选择Tomcat?
  2. 你能在 Eclipse 中启动和停止 Tomcat 吗?如果是这样,您可以打开浏览器并导航到http://localhost:8080- 应显示 Tomcat 控制台。检查日志应该没有任何错误。
  3. 您应该能够右键单击您的 Web 项目并说在服务器上运行并选择 Tomcat。或者,在服务器视图中右键单击 Tomcat 服务器并选择添加和删除。
  4. 如果第 3 步不起作用,则可能是导入的项目有错误。可能引用了不存在的库或无效的路径。打开问题视图,看看是否有任何编译错误。打开错误视图,看看是否有任何 eclipse 错误。右键单击项目-> 构建路径-> 配置构建路径。检查参考库并查看是否有任何错误或警告。
  5. 如果以上一切都有效,但仍然没有取得任何进展,请尝试从头开始创建一个简单的动态 Web 应用程序并在服务器上运行它。

回答by yves.beutler

If you import an exported dynamic web project, eclipse will import it as a java project. You have to change the project type manually. For example like this: convert java project to dynamic web project

如果导入导出的文件dynamic web project,eclipse 会将其导入为java project. 您必须手动更改项目类型。例如像这样:将 java 项目转换为动态 web 项目

回答by David

OK. My experience is not exactly the same as the poster, but rather than ask a similar question and answer it myself, I'll add my two pennyworth here.

好的。我的经历与海报不完全相同,但与其提出类似的问题并自己回答,我将在这里添加我的两个便士。

When I have tried to import a dynamic web project from work onto my home machine — both Eclipse projects — using

当我尝试将一个动态 Web 项目从工作导入到我的家用机器上时——两个 Eclipse 项目——使用

Import -> Existing Projects into Workspace

导入 -> 现有项目到工作区

I have always ended up with a red exclamation mark against my imported project. Googling indicates that this means the project contains build path errors. Following the advice in the ticked answer above I

我的导入项目总是以红色感叹号结束。谷歌搜索表明这意味着该项目包含构建路径错误。按照上面勾选答案中的建议,我

"Right click the project -> Build path -> Configure build path".

“右键单击项目-> 构建路径-> 配置构建路径”。

There I find that the JRE System Library has a red cross against it. What to do? This worked:

在那里,我发现 JRE 系统库对它有一个红十字。该怎么办?这有效:

  1. Delete the JRE System library entry using the Remove button.

  2. Click the Add Library button and select JRE System library. I accepted the default Workspace default JRE.

  1. 使用删除按钮删除 JRE 系统库条目。

  2. 单击添加库按钮并选择 JRE 系统库。我接受了默认的 Workspace 默认 JRE。

So I don't have the reconstruction fag any more. (I assume there must be differences between the installations on the two machines, although both are running the same version of Mac OS.)

所以我不再有重建同性恋了。(我认为两台机器上的安装肯定存在差异,尽管两者都运行相同版本的 Mac OS。)

回答by Bobby Martin

On the dialog before you get the "The selection cannot be run on any server" alert, in the upper right side it tells you why you can't add it to the selected server. For me, it was because my Tomcat 8.0 server couldn't run JRE 1.8 projects.

在收到“无法在任何服务器上运行选择”警报之前的对话框中,右上角会告诉您为什么无法将其添加到所选服务器。对我来说,这是因为我的 Tomcat 8.0 服务器无法运行 JRE 1.8 项目。

I solved it by creating a new Tomcat 8.0 server, changing the runtime environment from Tomcat 8.0 to my 1.8 jre. Then I could run my project on the new server.

我通过创建一个新的 Tomcat 8.0 服务器,将运行时环境从 Tomcat 8.0 更改为我的 1.8 jre 来解决它。然后我可以在新服务器上运行我的项目。