test maven web module in eclipse and tomcat - eclipse

I have a maven web module in my eclipse project.
Is it possible to simply test this module in eclipse by running it on tomcat.
At the minute im generating a war file and adding it to the webapps directory of tomcat.
A quicker approach would be great
Thanks
Damien

Is it possible to simply test this module in eclipse by running it on tomcat.
You could deploy your application on Tomcat using the WTP. This is doable whether you're using the Maven Eclipse Plugin or the m2eclipse plugin (just make sure to install the Maven Integration for WTP from the m2eclipse Extras).

I'd recommend that you try the maven jetty plugin.
http://maven.apache.org/plugins/maven-war-plugin/examples/rapid-testing-jetty6-plugin.html

If you could accept to use Jetty to test it ,
it's more easier to use Eclipse Run-Jetty-Run Plugin to run your project , just one click without any configuration!
Reference
http://code.google.com/p/run-jetty-run/

Related

How to run maven webapp from eclipse with embedded tomcat?

I can run a normal dynamic web app from eclipse with embedded tomcat. I found it very convenient for testing and debugging. However, I cannot run a maven webapp from my eclipse with embedded tomcat. I have set the run configurations for the project properly. And after I click run on the "Run Configurations" window, the tomcat server is started successfully. However, my maven web app does not start (the homepage of the app is not displayed on the web browser). Can anyone help me on this? Thanks in advance!
The M2E Maven Eclipse plugin provides an integration with the Eclipse WTP Project called M2E-WTP which provides the functionality you are looking for.

Eclipse not deploy all the jar files for a web app

We have a non-trivial multi-module maven project, then have a single module maven web-app that depends on 2 modules in the larger multi module project.
When we use eclipse to deploy to tomcat, it doesn't deploy all the jars that are required (spring, camel, etc) by the projects in the multi-module projects, but the multi-module jars are present???
But if we were to do an export of a war file on the single module app it includes everything we need spring, camel, and all the multi-module jars as expected? Why do export and deploy work differently and how can I get deploy to work the way I want.
We are using eclipse 3.6.2 with m2eclipse and other plugins. It seems Eclipse Indigo is worst at handling maven projects than 3.6.
This seems to be the same problem that I encounter semi-regularly. Open the build path for the project, and in the Exports tab, check the Maven dependencies checkbox. Do a clean and reploy the webapp.
It may be necessary to remove & readd the webapp to the server, and I usually have to quit Eclipse and restart it.

deploying a war file in WTP(Eclipse) tomcat server

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

Maven/Jetty to Maven/Tomcat Project

I have a project that I created with the Maven Archetype plugin and I added the Maven Jetty plugin so I can run the jetty server with "mvn jetty:run-war".
Now I have to change my project so that it integrates with Eclipse and Tomcat. I remember working on some projects which when I clicked the Tomcat button from the Sysdeo Eclipse Tomcat Launcher plugin, it would automatically compile the new code, deploy it to the Tomcat's webapp folder, and start the Tomcat server for you. Using tomcat also allows us to use the integrated Eclipse debugger.
How do I get that effect with my current Maven/Jetty setup without re-creating the entire project over again and starting it as a Tomcat project?
You can try using Tomcat Maven Plugin. It has similar goals to the jetty plugin. You just need to add the plugin configuration to your existing pom and make no additional changes.

Integrate War-Plugin for m2eclipse into Eclipse Project

I set up a small web project with JSF and Maven. Now I want to deploy on a Tomcat server. Is there a possibility to automate that like a button in Eclipse that automatically deploys the project to Tomcat?
I read about a the Maven War Plugin but I couldn't find a tutorial how to integrate that into my process (eclipse/m2eclipse).
Can you link me to help or try to explain it. Thanks.
I set up a small web project with JSF and maven. Now I want to deploy on a Tomcat Server.
During development I recommend to use Eclipse Web Tools Platform (WTP). M2Eclipse provides support for it (assuming you have Maven Integration for WTP installed) and your project should be recognized as a Dynamic Web Project runnable on a Server.
So, declare Tomcat as a Server (show the Servers view and right-click in it to add a Server via New > Server). And deploy your project to it (right-click on your project then Run > Run on Server).
There are other options like using the Tomcat Maven Plugin or the generic Cargo Maven Plugin but I wouldn't use them for development and, since you are a Maven beginner, I don't recommend them at all. Use your IDE.
I read about a the Maven War Plugin but I couldn't find a tutorial how to integrate that into my process.
Actually, the Maven War Plugin is only responsible of the packaging of your webapp project (it is bound automatically on the package phase when using a <packaging>war<packaging> for your project). It isn't used for deployment. But as I said, use your IDE to deploy your application during development.
The war plugin is for generating war files, not for deploying them. What you are asking for may be provided by the Cargo Plugin. Another interesting candidate for you could be the jetty-maven-plugin.