4

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.

Added server as tomcat version 7 in eclipse indigo 3.7. Server started. But my war file didn't deployed in the server.

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".

How can i deploy my war file in the eclipse WTP tomcat server?. Do i need to run any maven target?

TechFind
  • 3,696
  • 18
  • 47
  • 62

5 Answers5

11

Make sure that you have "Maven Integration for WTP" installed in your Eclipse instance.

First check if it's available through

  • Window->Preferences->Maven->Discovery->Open Catalog

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):

https://repository.sonatype.org/content/repositories/forge-sites/m2eclipse-wtp/0.13.0/S/0.13.0.20110623-0455

This integration does a lifecycle mapping of maven-war-plugin into m2e architecture.

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...

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).

Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
  • After hitting wall for 2 hours I came across your comment. I had both WTP and M2E installed but no m2e-wtp. I tried everything except that one small (forgotten) thing. The behavior of Tomcat was like it didn't do deployment at all. Now, after adding m2e-wtp, everything works like a charm. – omnomnom Aug 02 '13 at 22:18
  • @PiotrekDe. Thankfully, it all comes prepackaged now with Kepler JEE bundle. – Alexander Pogrebnyak Aug 03 '13 at 18:03
5

I think eclipse is not recognizing your project as a web app, To confirm this

  • Open to do open J2ee perspective on your eclipse, If you open the project folder of your app, You should see (Deployment Descriptor) enter image description here

  • 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

    enter image description here

  • If you do that the local tomcat server will add your app when do add remove projects

Prasanna Talakanti
  • 2,354
  • 1
  • 16
  • 16
  • Great tip. I also had to follow this step: 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/ – cowls May 26 '13 at 09:22
  • This doesn't work for maven projects. This creates an additional WEB-INF folder which doesn't follow the maven folder structure. – Varun Achar Aug 22 '14 at 07:22
  • +1 for "You should see (Deployment Descriptor) " comment. Mine was not showing that in J2EE Perspective when I expanded my app in project explorer. – supernova Nov 29 '17 at 08:52
1

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.

Asokan
  • 99
  • 1
  • 4
0

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.

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"

Where I could see my exploded app deployed but it was not having any /classes folder just limited files.

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 Module has actually populated "R-click project > Properties > Deployment Assembly " This Web Deployment Assembly window 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. enter image description here

supernova
  • 3,111
  • 4
  • 33
  • 30
0

If you have Eclipse 3.5 or above you should ensure that you have both the m2eclipse (m2e for 3.7) plugin installed and its WTP add-on. With these you shouldn't need to change your configuration by hand.

Did you try to build your project from the command line and deploy it in Tomcat by hand?

By the way, have you read this wiki post? It's a bit old, but it may still be relevant.

Nicola Musatti
  • 17,834
  • 2
  • 46
  • 55