在 WTP(Eclipse) tomcat 服务器中部署一个战争文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7482312/
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
deploying a war file in WTP(Eclipse) tomcat server
提问by TechFind
I have a maven build Java project. My war file name is: test-1.0-SNAPSHOT.war I am using M2E plugin in Eclipse. I have run target mvn package.
我有一个 Maven 构建 Java 项目。我的War文件名是:test-1.0-SNAPSHOT.war 我在 Eclipse 中使用 M2E 插件。我已经运行了 target mvn package。
Added server as tomcat version 7 in eclipse indigo 3.7. Server started. But my war file didn't deployed in the server.
在 eclipse indigo 3.7 中添加服务器作为 tomcat 版本 7。服务器启动。但是我的war文件没有部署在服务器上。
I have tried by right clicking tomcat server and Add remove..., it says "there is no resources that can be added or removed from the server".
我尝试通过右键单击tomcat服务器并添加删除...,它说“没有可以从服务器添加或删除的资源”。
How can i deploy my war file in the eclipse WTP tomcat server?. Do i need to run any maven target?
如何在 eclipse WTP tomcat 服务器中部署我的 war 文件?我需要运行任何 Maven 目标吗?
回答by Alexander Pogrebnyak
Make sure that you have "Maven Integration for WTP" installed in your Eclipse instance.
确保在 Eclipse 实例中安装了“Maven Integration for WTP”。
First check if it's available through
首先检查它是否可用
- Window->Preferences->Maven->Discovery->Open Catalog
- 窗口->首选项->Maven->发现->打开目录
If for whatever reason this does not work, you can get WTP integration from this update site (that's the version I am currently using):
如果由于某种原因这不起作用,您可以从这个更新站点(这是我目前使用的版本)获得 WTP 集成:
This integration does a lifecycle mapping of maven-war-plugin into m2e architecture.
这种集成将 maven-war-plugin 的生命周期映射到 m2e 架构。
Once you've installed the WTP integration, you must restart eclipse and once it's restarted, right click on your web app project and choose: Maven->Update Project Configuration...
一旦您安装了 WTP 集成,您必须重新启动 eclipse,一旦它重新启动,右键单击您的 Web 应用程序项目并选择:Maven->更新项目配置...
Also, I would advise to run a clean build at this time.
另外,我建议此时运行一个干净的构建。
Last, but not least, delete and recreate your Tomcat server configuration (I don't know why, but I had to do it quite a few times when I switched to m2e).
最后但并非最不重要的是,删除并重新创建您的 Tomcat 服务器配置(我不知道为什么,但是当我切换到 m2e 时我不得不这样做很多次)。
回答by Prasanna Talakanti
I think eclipse is not recognizing your project as a web app, To confirm this
我认为 Eclipse 没有将您的项目识别为 Web 应用程序,以确认这一点
Open to do open J2ee perspective on your eclipse, If you open the project folder of your app, You should see (Deployment Descriptor)
If you don't see it, your app is not web app as far as eclipse is concerned
- I have see this in case if you imported/created a maven command line project
- To fix this
Select Project ==> Properties ==> Project Facets ==> make sure Dynamic Web Module check box is checked
If you do that the local tomcat server will add your app when do add remove projects
打开在你的eclipse上打开J2ee透视图,如果你打开你的应用程序的项目文件夹,你应该看到(部署描述符)
如果您没有看到它,就 eclipse 而言,您的应用程序不是网络应用程序
- 如果您导入/创建了 Maven 命令行项目,我会看到这一点
- 要解决这个问题
选择项目 ==> 属性 ==> 项目方面 ==> 确保选中动态 Web 模块复选框
如果您这样做,本地 tomcat 服务器将在添加删除项目时添加您的应用程序
回答by Asokan
I think eclipse is not recognizing your project as web app,convert your project into web app by command mvn eclipse:eclipse -Dwtpversion=2.0 and try to deploy in Eclipse configured tomcat,it will work.
我认为 eclipse 没有将您的项目识别为 Web 应用程序,通过命令 mvn eclipse:eclipse -Dwtpversion=2.0 将您的项目转换为 Web 应用程序并尝试在 Eclipse 配置的 tomcat 中部署,它会工作。
回答by supernova
Adding 2 cents to Prasanna wonderful solution. I realized that building maven war files "mvn package" was just creating .war file but eclipse was not picking up that war but was deploying its some internal version of it's app war.
为 Prasanna 美妙的解决方案添加 2 美分。我意识到构建 Maven War文件“mvn 包”只是在创建 .war 文件,但 Eclipse 并没有接受该War,而是在部署其应用程序War的某些内部版本。
I found that server > Browse Deployment Location.. in Eclipse server view .. it was taking to some abstract location like "C:\Programs\workspaceSTS.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps"
我发现服务器 > 浏览部署位置.. 在 Eclipse 服务器视图中.. 它正在进入一些抽象位置,如“C:\Programs\workspaceSTS.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps”
Where I could see my exploded app deployed but it was not having any /classes folder just limited files.
在那里我可以看到我部署的爆炸应用程序,但它没有任何 /classes 文件夹,只有有限的文件。
Using Prasanna's method I realized that eclipse now was deploying full exploded .war now.
So this was happening coz changing the facets to Dynamic Web Modulehas actually populated "R-click project > Properties > Deployment Assembly"
This Web Deployment Assemblywindow only tells eclipse what to deploy and what not. So even if your project is NOT setup as Dynamic Web Module , and still if you configure "Web Deployment Assembly" values properly , eclipse will deploy the app fine to Tomcat/ Server.
使用 Prasanna 的方法,我意识到 eclipse 现在正在部署完全爆炸的 .war。所以这发生了因为将方面更改为 动态 Web 模块实际上填充了“R 单击项目 > 属性 >部署程序集”这个Web 部署程序集窗口只告诉 eclipse 部署什么,不部署什么。因此,即使您的项目没有设置为动态 Web 模块,并且如果您正确配置了“Web 部署程序集”值,eclipse 也会将应用程序部署到 Tomcat/服务器。
回答by Nicola Musatti
If you have Eclipse 3.5 or above you should ensure that you have both the m2eclipse(m2efor 3.7) plugin installed and its WTPadd-on. With these you shouldn't need to change your configuration by hand.
如果你有 Eclipse 3.5 或更高版本,你应该确保你已经安装了m2eclipse(m2efor 3.7)插件和它的WTP插件。有了这些,您不需要手动更改配置。
Did you try to build your project from the command line and deploy it in Tomcat by hand?
您是否尝试从命令行构建项目并手动将其部署在 Tomcat 中?
By the way, have you read this wiki post? It's a bit old, but it may still be relevant.
顺便说一句,你读过这篇维基帖子吗?它有点旧,但它可能仍然相关。