简体   繁体   English

将动态 Web 项目导入 Eclipse

[英]Importing Dynamic Web Project into Eclipse

I've been working on a dynamic web project in Eclipse.我一直在 Eclipse 中开发一个动态 Web 项目。 I have recently reInstalled my OS and I use a clean eclipse.我最近重新安装了我的操作系统并且我使用了一个干净的 Eclipse。 I can import my web project, but when I try to lunch (run on server) I always get this message:我可以导入我的 Web 项目,但是当我尝试吃午饭(在服务器上运行)时,我总是收到以下消息:

"The selection cannot be run on any server"

I installed the eclipse's tomcat plugin, and it works fine.我安装了eclipse的tomcat插件,运行正常。 I set the tomcat library too.我也设置了 tomcat 库。 (window/preferences/tomcat). (窗口/首选项/ tomcat)。

What's the problem with it?它有什么问题?

If you import an exported dynamic web project , eclipse will import it as a java project .如果您导入一个导出的dynamic web project ,eclipse 会将它作为一个java project导入。 You have to change the project type manually.您必须手动更改项目类型。 For example like this: convert java project to dynamic web project例如像这样: 将 java 项目转换为动态 web 项目

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.如果我对您的理解正确,您已经将以前工作的 Web 项目导入到 Eclipse(和操作系统)的全新安装中,并且您正准备在 Tomcat 上运行该项目。 There could be a number of reasons why it isn't working, here are some things to consider in troubleshooting:它不工作的原因可能有很多,以下是故障排除时需要考虑的一些事项:

  1. First thing to validate is whether or not Tomcat has been installed correctly and is running without errors.首先要验证的是 Tomcat 是否已正确安装并且运行时没有错误。 You say you installed a Tomcat plugin for Eclipse.你说你为 Eclipse 安装了一个 Tomcat 插件。 I didn't know there was one.我不知道有一个。 I usually install Tomcat separately and then configure Tomcat settings in Eclipse.我一般是单独安装Tomcat,然后在Eclipse中配置Tomcat设置。 Or did you install Tomcat via the Servers view?或者您是否通过服务器视图安装了 Tomcat? Windows -> View -> Other -> Server -> Servers, right click in Server view and go New -> Server. Windows -> 查看 -> 其他 -> 服务器 -> 服务器,在服务器视图中右键单击并转到新建 -> 服务器。 Select Apache and then Tomcat?选择Apache,然后选择Tomcat?
  2. Can you start and stop Tomcat within Eclipse?你能在 Eclipse 中启动和停止 Tomcat 吗? If so can you open a browser and navigate to http://localhost:8080 - a Tomcat console should display.如果是这样,您可以打开浏览器并导航到http://localhost:8080 - 应显示 Tomcat 控制台。 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.您应该能够右键单击您的 Web 项目并说在服务器上运行并选择 Tomcat。 Alternatively in the Server view right click on the Tomcat server and select Add and Remove.或者,在服务器视图中右键单击 Tomcat 服务器并选择添加和删除。
  4. If the 3rd step didn't work it is possible that the imported project has errors.如果第 3 步不起作用,则可能是导入的项目有错误。 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.打开错误视图,看看是否有任何 eclipse 错误。 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.如果以上一切都有效,但仍然没有取得任何进展,请尝试从头开始创建一个简单的动态 Web 应用程序并在服务器上运行它。

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.在那里,我发现 JRE 系统库对它有一个红十字。 What to do?该怎么办? This worked:这有效:

  1. Delete the JRE System library entry using the Remove button.使用删除按钮删除 JRE 系统库条目。

  2. Click the Add Library button and select JRE System library.单击添加库按钮并选择 JRE 系统库。 I accepted the default Workspace default 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。)

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.我通过创建一个新的 Tomcat 8.0 服务器,将运行时环境从 Tomcat 8.0 更改为我的 1.8 jre 来解决它。 Then I could run my project on the new server.然后我可以在新服务器上运行我的项目。

I know this is too late but it will help a googler who accidentally stumbled here while chasing the rabbit hole.我知道这为时已晚,但它会帮助一个在追逐兔子洞时不小心在这里绊倒的谷歌员工。 Make sure java version stated in the project facet is compatible with your tomcat.确保项目方面中声明的 java 版本与您的 tomcat 兼容。 Project facet->java (you can right click and change the version)项目facet->java(可以右键更改版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM