Prereqs
- WTP 2.0.2 or later or Eclipse for Java EE developers bundle
- Tomcat 6.0.16 or other web application server supported by WTP
- m2eclipse 0.9.4 or later with "Maven Integration for WTP" feature installed
Define Tomcat 6.0 server runtime
- Window / Preferences / Server / Installed Runtimes / Add...
- In New Server Runtime dialog select Apache, Apache Tomcat v6.0
- Select tomcat 6.0 installation
Create new webapp using maven-archetype-webapp archetype
- Open "New Maven Project" wizard from File / New... / Maven Project.
- Leave default values on the first wizard page.
Select maven-archetype-webapp archetype and go to the next page.
| If no archetypes appear in this view make sure that the "Maven Central repository index" feature is installed or index for http://repo1.maven.org/maven2/ is manually registered in the Maven Indexes view |
!
Specify groupId, artifactId and optionally package name for generated Java classes, e.g. m2eclipse.howto and webapp and press Finish.
Wizard will create new webapp project and configure it to work with WTP.
Launch web application on the server
- Right click on the project, Run As -> Run On Server
- Press Finish to let WTP create server configuration and run webapp on the server
After WTP deploys webapp and start the server you should see "Hello World!" page
Create java source folder
- Standard Maven convention for java sources is src/main/java folder. Create this folder by drilling down to src/main then right click -> new folder. You will need right click the project and run Maven -> Update Project Configuration as you have added a new source folder.
| If you need to troubleshoot, jars for your project are located in a subfolder below \.metadata\.plugins\org.eclipse.wst.server.core\ . You will need to explore the subfolders to locate the actual location where the web application is being assembled. |
Add Servlet and JSP dependencies
Many JEE web applications have dependencies on javax.servlet:servlet-api and javax.servlet:jsp-api. These required at compile time, but should not be packaged with web application, because they are provided by the application server (e.g. see tomcat/lib folder). The provided scope is used to handle such dependencies. Add the following lines to your pom.xml:
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency>
Comments (6)
May 29
Andrew Myers says:
I'm sure I've followed these instructions to the letter,...I'm sure I've followed these instructions to the letter, however when I right click on the project and choose "Run As -> Run On Server" as described in the section "Launch web application on the server" I get the following error in a pop-up dialog:
"The selection did not contain anything that can be run on a server"
Any suggestions as to what is happening?
Andrew
Aug 13
Chris Lacy says:
I have a similar problem to Andrew. When I get to the same step (right cli...I have a similar problem to Andrew. When I get to the same step (right click on project, "Run As -> Run On Server") the "Run On Server" option is not there.
m2eclipse 0.9.6
eclipse 3.4.0
Fedora 9
Follow Up:
This was on an underpowered (~1ghz, ~512M) box. I've got it working on both an underpowered Windows XP box and a high powered 64 bit Fedora box. Thanks for replying, Eugene. This is the best setup ever!
Aug 07
Eugene Kuleshov says:
Chris, please make sure that you have installed "Maven Integration for WTP" feat...Chris, please make sure that you have installed "Maven Integration for WTP" feature in m2eclipse.
Aug 28
Ricardo Mayerhofer says:
Is it possible to use WTP integration with an existing project?Is it possible to use WTP integration with an existing project?
Aug 28
Eugene Kuleshov says:
Ricardo, you can use "Maven / Update project configuration" to configure existin...Ricardo, you can use "Maven / Update project configuration" to configure existing project. Note that your project should have pom.xml with corresponding packaging (currently only "war" packaging is supported, but we are working on adding support for "ejb" and "ear") and maven-war-plugin configuration. In other words, your project should build with Maven, you can find some examples on Maven web site.
In a long term we will provide support for converting Eclipse configuration back to Maven, but currently it is not supported.
Oct 03
Renato de Melo says:
Can I use "WTP Integration" to create a "Dynamic Web Project" using JSF 1.2 and ...Can I use "WTP Integration" to create a "Dynamic Web Project" using JSF 1.2 and targeting "Websphere Application Server Community Edition"?
Is there any howto available?
Thanks