如何在 Eclipse 中将我的应用程序添加到 Tomcat?

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

How can I add my application to Tomcat in Eclipse?

eclipsetomcatmaven

提问by Aaron

I have a web app built with Maven. Most of the time, I built the application using Intellij IDEA, but now I want to import the application in Eclipse to see something in this IDE.

我有一个用 Maven 构建的网络应用程序。大多数时候,我使用 Intellij IDEA 构建应用程序,但现在我想在 Eclipse 中导入应用程序以在此 IDE 中查看某些内容。

After mvn eclipse:eclipse, I add in Eclipse the app, but when I try to add the app to the server (tomcat), I receive:

之后mvn eclipse:eclipse,我在 Eclipse 中添加了应用程序,但是当我尝试将应用程序添加到服务器(tomcat)时,我收到:

There are no resources that can be added or removed from the server

Solutions?

解决方案?

回答by ClutchDude

You need the project to have a Eclipse Dynamic Web Module facet. You can try doing this via the project properties dialog and looking at project facets, then clicking the appropriate check box. This may not be available however, so you may need to do the next thing.

您需要项目具有 Eclipse 动态 Web 模块方面。您可以尝试通过项目属性对话框执行此操作并查看项目方面,然后单击相应的复选框。但是,这可能不可用,因此您可能需要执行下一步操作。

Create a backup of your project and follow the directions at dzone.com. This'll allow you to modify the project facets via your eclipse .project file.

创建项目的备份并按照dzone.com 上的说明进行操作。这将允许您通过 eclipse .project 文件修改项目方面。

Keep in mind, once you add those facets, you cannot change them back via Eclipse. Definitely make sure you have a backup before starting.

请记住,一旦添加了这些方面,就无法通过 Eclipse 将它们改回来。在开始之前一定要确保你有一个备份。

回答by MAB

This step worked for me:

这一步对我有用:

Right-Click on the Project Name, then Maven-->Update Project.. Click OK

右键单击项目名称,然后 Maven--> 更新项目.. 单击确定

After doing this I was able to see my project in Add/Remove Programs.

完成此操作后,我能够在“添加/删除程序”中看到我的项目。

As mentioned somewhere else adding Eclipse WTP didn't do any good, however I performed the above step after I had already added Eclipse WTP, so I am guessing that may not be needed. This was done for Eclipse Juno.

正如其他地方提到的,添加 Eclipse WTP 没有任何好处,但是我在添加 Eclipse WTP 之后执行了上述步骤,所以我猜这可能不需要。这是为 Eclipse Juno 完成的。

Hope this helps someone.

希望这可以帮助某人。

Edited: You can follow this link as above mentioned I think might have needed WTP and that add a lot of other things into the workspace.

编辑:您可以按照上面提到的这个链接进行操作,我认为可能需要 WTP 并将许多其他内容添加到工作区中。

http://blog.teamextension.com/maven-as-eclipse-dynamic-web-module-556

http://blog.teamextension.com/maven-as-eclipse-dynamic-web-module-556

回答by Mohammed Irfan Tirupattur

  1. Check whether Maven Integration for Eclipse WTPis installed. If not, install it from Eclipse Marketplace
  2. After installation restart Eclipse
  3. Right click your project and Maven--> update project configuration
  4. Delete tomcat and re create tomcat (clean tomcat,add your project,publish and enjoy)
  1. 检查是否Maven Integration for Eclipse WTP安装。如果没有,请从 Eclipse Marketplace 安装
  2. 安装后重启Eclipse
  3. 右键单击您的项目,然后 Maven--> update project configuration
  4. 删除tomcat,重新创建tomcat(清理tomcat,添加项目,发布享受)

回答by Marvo

I've got Tomcat 6, Java 1.6, and was trying to get it to work in Eclipse Juno Service Release 1's "internal server" (whatever that's called.) Here's what I did that worked for me:

我有 Tomcat 6、Java 1.6,并试图让它在 Eclipse Juno Service Release 1 的“内部服务器”(不管它叫什么)中工作。这是我所做的对我有用的:

(Found these instructions at http://www.mkyong.com/eclipse/eclipse-ide-tomcat-version-6-0-only-supports-j2ee-1-2-1-3-1-4-and-java-ee-5-web-modules/)

(在http://www.mkyong.com/eclipse/eclipse-ide-tomcat-version-6-0-only-supports-j2ee-1-2-1-3-1-4-and-java找到这些说明-ee-5-web-modules/)

  1. I should point out that I followed ClutchDude's instructions to make my project a Dynamic Web Module facet. It didn't work on its own for me, but maybe it was part of making it work in the end.

  2. Using Eclipse (or other text editor), open the file

    .settings/org.eclipse.wst.common.project.facet.core.xml

  3. Find the line that reads

    <installed facet="jst.web" version="3.0"/>

  4. 3.0 is for Tomcat 7.x (so says mkyong.) Change it to 2.5 (or 2.4).

  1. 我应该指出,我按照 ClutchDude 的说明使我的项目成为动态 Web 模块方面。它对我来说并没有单独工作,但也许它是最终使其工作的一部分。

  2. 使用 Eclipse(或其他文本编辑器)打开文件

    .settings/org.eclipse.wst.common.project.facet.core.xml

  3. 找到读取的行

    <installed facet="jst.web" version="3.0"/>

  4. 3.0 适用于 Tomcat 7.x(mkyong 这么说)。将其更改为 2.5(或 2.4)。

I restarted Eclipse and it worked for my project.

我重新启动了 Eclipse,它适用于我的项目。

回答by ArunM

The reason why this is happening is because eclipse by default looks for the deployment descriptor in the folder {project.home}/Webcontent/WEB-INF/web.xml where as the Maven puts them in src/main/webapp/WEB-INF/web.xml.

发生这种情况的原因是因为 Eclipse 默认在文件夹 {project.home}/Webcontent/WEB-INF/web.xml 中查找部署描述符,而 Maven 将它们放在 src/main/webapp/WEB-INF /web.xml。

So when you are trying to add your project onto the server eclipse cannot find a deployment descriptor and hence you get the annoying message.

因此,当您尝试将项目添加到服务器时,eclipse 找不到部署描述符,因此您会收到烦人的消息。

This can be solved by adding the following entries in .settings/org.eclipse.wst.commonwhich can be found in

这可以通过在.settings/org.eclipse.wst.common 中添加以下条目来解决,该条目可以在

  1. Project home folder in your workspace if it is a new maven project.
  2. The folder where you already imported from if you are using Import -> Maven projects.
  1. 如果是新的 Maven 项目,则在工作区中的项目主文件夹。
  2. 如果您使用 Import -> Maven 项目,则您已经从中导入的文件夹。

Make the following changes in to the org.eclipse.wst.common

对 org.eclipse.wst.common 进行以下更改

  1. wb-resource deploy-path="/" source-path="/src/main/webapp"/. Add this entry.
  2. Edit --> property name="java-output-path"
  1. wb-resource deploy-path="/" source-path="/src/main/webapp"/. 添加此条目。
  2. 编辑 --> 属性名称="java-output-path"

Please check the following link from more details. http://java.dzone.com/articles/webapps-eclipse-and-maven. The comments section has an excellent example with a working project.

请查看以下链接了解更多详情。http://java.dzone.com/articles/webapps-eclipse-and-maven。评论部分有一个很好的例子,有一个工作项目。

回答by Victor Powell

This issue was fixed for me my installing additional eclipse modules. in particular, the ones related to m2e-wtp. just do a search for m2ein the plugins search listing for your version of eclipse

这个问题在我安装额外的 eclipse 模块时得到了解决。特别是与 m2e-wtp 相关的那些。只需m2e在插件搜索列表中搜索您的 eclipse 版本

回答by Héctor Gallego

Maybe you don't need add your application to the server's configuration. I think that you must use m2e eclipse plugin in order to launch the app.

也许您不需要将应用程序添加到服务器的配置中。我认为您必须使用 m2e eclipse 插件才能启动该应用程序。

For example, in your eclipse you will see a contextual menu called "Run as" if you right-click on your pom file. You can clicking on "Maven build" and Maven will download all the information needed to start tomcat.

例如,在您的 Eclipse 中,如果您右键单击您的 pom 文件,您将看到一个名为“运行方式”的上下文菜单。您可以单击“Maven build”,Maven 将下载启动 tomcat 所需的所有信息。

I hope this helps you.

我希望这可以帮助你。

回答by sofs1

I used

我用了

 mvn eclipse:eclipse -Dwtpversion=2.0 

in command line in the folder where I had my pom.xml. Then I refreshed the project in eclipse IDE. After that I was able to add my project.

在我有 pom.xml 的文件夹中的命令行中。然后我在eclipse IDE中刷新了项目。之后我就可以添加我的项目了。

回答by Mark F Guerra

I was able to resolve this by removing my EAR project from my Eclipse workspace, then re-importing it.

我能够通过从我的 Eclipse 工作区中删除我的 EAR 项目,然后重新导入它来解决这个问题。

回答by Hinotori

Well, with a Spring and maven project, i got it that way:

好吧,通过 Spring 和 maven 项目,我是这样理解的:

  • Eclipse Version: 2019-06 (4.12.0)
  • Java 1.8
  • Tomcat 7
  • Eclipse 版本:2019-06 (4.12.0)
  • 爪哇 1.8
  • 雄猫 7

Yes, go to Project Properties >> Facets >> select Dynamic Web Module but dont apply yet!!!

是的,转到 Project Properties >> Facets >> 选择 Dynamic Web Module,但还没有申请!!!

Right under, it should appear a link Further Configuration Available. Click on it, otherwise one will have to edit .settings/org.eclipse.wst.common.component manually. Update source directory to src/main/java. (source)

在它的正下方,应该会出现一个链接“进一步的配置可用”。单击它,否则必须手动编辑 .settings/org.eclipse.wst.common.component。将源目录更新为 src/main/java。(来源

Then in Facets window check Java - mine was pointing to 11 even though i don't have Java 11 installed or configured like a JRE runtime. I could only add/remove when changed to 1.8. (source). Note: That was really the problem, why don't Eclipse get this configuration automatically from the project?

然后在 Facets 窗口中检查 Java - 即使我没有像 JRE 运行时那样安装或配置 Java 11,我的也指向 11。我只能在更改为 1.8 时添加/删除。(来源)。注意:这确实是问题所在,为什么 Eclipse 不从项目中自动获取此配置?

Finally Eclipse creates some directories like WEB-INF and META-INF, just delete them.

最后 Eclipse 会创建一些目录,如 WEB-INF 和 META-INF,删除它们即可。