| <html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link type="text/css" href="../../../../../default_style.css" rel="stylesheet"><link type="text/css" href="../../../../../webtools/wtp.css" rel="stylesheet"><title>Integrating existing maven project in Eclipse WTP.</title></head><body><table border="0" cellpadding="2" cellspacing="5" width="100%"><tbody><tr><td align="left" width="60%"><font class="indextop">jst j2ee</font><br><font class="indexsub">Integrating existing maven project in Eclipse WTP.</font></td><td width="40%"><img src="../../../../../webtools/images/wtplogosmall.jpg" align="middle" height="129" hspace="50" width="207" alt="WTP Logo" usemap="logomap"><map id="logomap" name="logomap"><area coords="0,0,207,129" href="/webtools/" alt="WTP Home"></map></td></tr></tbody></table><table border="0" cellpadding="2" cellspacing="5" width="100%"><col width="16"><col width="*"><tbody><tr><td colspan="2" align="left" bgcolor="#0080c0" valign="top"><b><font color="#ffffff" face="Arial,Helvetica">Intoduction</font></b></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><p>This article walkthroughs the steps required to integrate an existing maven project structure |
| in the eclipse WTP platform. This integration uses the flexibile project structure introduced in |
| the WTP M3 release. |
| </p></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><br></td></tr><tr><td colspan="2" align="left" bgcolor="#0080c0" valign="top"><b><font color="#ffffff" face="Arial,Helvetica">Pre-requisites</font></b></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><p> |
| Maven should be installed and configured, if not it can be downloaded from |
| <a href="http://maven.apache.org/"> http://maven.apache.org/</a>.<br>This article also assumes |
| that you are familiar with maven project artifacts and the maven eclipse plugin. |
| </p></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><br></td></tr><tr><td colspan="2" align="left" bgcolor="#0080c0" valign="top"><b><font color="#ffffff" face="Arial,Helvetica">A Sample Maven Project : WebSample</font></b></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><p> |
| |
| Unzip <A href="resource/MavenWebSample.zip" target="_blank">MavenWebSample.zip</A>. |
| |
| Our MavenWebSample has two projects, a web project and a utility project. |
| The web project "csrweb" contains a HelloWorldServlet and a web resource |
| index.html.<br> The utility project "bedrock" has a class Util which is used by |
| HelloWorldServlet. <br><br> |
| Please build the utility project by going to command prompt and typing maven jar:install |
| and the web project by typing maven war:install |
| <br><br> |
| Here is the eclipse enabled project <A href="resource/WebSample.zip" target="_blank">WebSample.zip</A>. |
| |
| </p></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><br></td></tr><tr><td colspan="2" align="left" bgcolor="#0080c0" valign="top"><b><font color="#ffffff" face="Arial,Helvetica">Configuring the Web Project</font></b></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><ol> |
| |
| <li> |
| <p> |
| Add the follwing in the <b>project.xml</b> of the csrweb to set the bedrock as the dependent project of the csrweb, |
| since csrweb uses bedrock project, setting this dependency in the eclipse will make sure proper |
| project build order. |
| </p> |
| |
| <pre> |
| <dependency> |
| <groupId>WebSample</groupId> |
| <artifactId>bedrock</artifactId> |
| <version>1.0</version> |
| <properties> |
| <war.bundle>true</war.bundle> |
| <b><eclipse.dependency>true</eclipse.dependency></b> |
| </properties> |
| </dependency> |
| </pre> |
| |
| </li> |
| <li>Create a file <b>project.properties</b> under the csrweb folder, the folder where you |
| will find project.xml. Now add the following in this file. |
| <pre> |
| maven.eclipse.projectnatures=org.eclipse.jst.j2ee.web.WebNature,org.eclipse.jdt.core.javanature,org.eclipse.wst.common.modulecore.ModuleCoreNature |
| maven.eclipse.buildcommands=org.eclipse.wst.common.modulecore.DeployableModuleBuilder,org.eclipse.jdt.core.javabuilder,org.eclipse.jst.j2ee.web.LibDirBuilder,org.eclipse.wst.validation.validationbuilder,org.eclipse.jst.j2ee.LibCopyBuilder,org.eclipse.wst.common.modulecore.LocalDependencyResolver |
| </pre> |
| |
| |
| |
| </li> |
| |
| <li> |
| Now open the command prompt, go to the csrweb folder and execute "maven eclipse". |
| You will see that two files are generated <b> .project</b> and <b> .classpath </b> |
| <br> |
| <br> |
| |
| <p> |
| Open the .project and remove the first buildcommand javabuilder and the first nature |
| org.eclipse.jdt.core.javanature.<br> This is done to ensure that only one |
| entry of javabuilder and org.eclipse.jdt.core.javanature exists. <br>The correct order of builder and natures |
| are needed to ensure proper functionality.The final .project should look like this. |
| </p> |
| <img src="images/csrwebproject.JPG"> |
| |
| </li> |
| |
| <br> |
| <br> |
| <li> |
| Create a <b>.j2ee</b> file in the csrweb project |
| |
| <pre> |
| <?xml version="1.0" encoding="UTF-8"?> |
| <j2eesettings version="600"> |
| <moduleversion>23</moduleversion> |
| <webcontent>src/webapp</webcontent> |
| <context-root>csrweb</context-root> |
| </j2eesettings> |
| </pre> |
| The moduleversion denotes the servlet version, for e.g. enter 22 for Servlet version 2.2, 23 for 2.3 and 24 for 2.4,<br> |
| this should match the version specified in the project.xml, in the dependency section of the servletapi. |
| |
| </li> |
| |
| <br> |
| <br> |
| |
| <li> |
| Now create a <b>.wtpmodule</b> file in the csrweb project and put the following content. |
| The xsd of the .wtpmodule is defined elsewere in the WTP. |
| |
| |
| <pre> |
| <?xml version="1.0" encoding="UTF-8"?> |
| <project-modules id="moduleCoreId"> |
| <wb-module deploy-name="csrweb.war"> |
| <wb-module module-type-id="jst.web"/> |
| <wb-resource deploy-path="/" source-path="/csrweb/src/webapp"/> |
| <wb-resource deploy-path="/WEB-INF/classes" source-path="/csrweb/src/main/java"/> |
| |
| |
| <dependent-module deploy-path="WEB-INF/lib" handle="module:/resource/csrweb/Library.jar"> |
| <dependency-type>uses</dependency-type> |
| </dependent-module> |
| |
| <dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/bedrock/bedrock.jar" > |
| <dependency-type>uses</dependency-type> |
| </dependent-module> |
| </wb-module> |
| <wb-module deploy-name="Library.jar"> |
| <wb-module module-type-id="jst.utility"/> |
| <wb-resource deploy-path="/" source-path="/csrweb/LibraryContents"/> |
| </wb-module> |
| </project-modules> |
| |
| </pre> |
| |
| <p> |
| For quick overview the line <b><wb-resource deploy-path="/" source-path="/csrweb/src/webapp"/> </b>implies that |
| all the contents of source-path will be placed <br>in the csrweb/.deployables folder after the build. <br> |
| Similarly the line <b><wb-resource deploy-path="/WEB-INF/classes" source-path="/csrweb/src/main/java"/></b> <br>implies that |
| after the build of the java files under the source-path, all the .class will be in the csrweb/.deployables/WEB-INF/classes |
| </p> |
| </li> |
| |
| <br> |
| <li> |
| Note that you will have to create a folder META-INF and MANIFEST.MF manually and |
| add the necessary jars as per your requirement, eclipse WTP <br>as of now doesn't generate |
| this file. You will also need to put this file as the wb-resource in the .wtpmodule file as |
| described above.<br> |
| |
| The csrweb has the MANIFEST.MF in the folder csrweb/src/webapp/META-INF |
| </li> |
| |
| </ol></td></tr><tr><td colspan="2" align="left" bgcolor="#0080c0" valign="top"><b><font color="#ffffff" face="Arial,Helvetica">Configuring the Util project</font></b></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><p> |
| <ol> |
| <li> |
| Create <b>project.properties </b> in the bedrock folder |
| |
| <pre> |
| maven.eclipse.projectnatures=org.eclipse.wst.common.modulecore.ModuleCoreNature |
| maven.eclipse.buildcommands=org.eclipse.wst.common.modulecore.DeployableModuleBuilder,org.eclipse.jdt.core.javabuilder,org.eclipse.wst.common.modulecore.LocalDependencyResolver |
| </pre> |
| </li> |
| |
| <li> |
| Now open the command prompt, go to the bedrock folder and execute "maven eclipse". |
| You will see that two files are generated <b> .project</b> and <b> .classpath </b> |
| <br> |
| <br> |
| |
| <p> |
| Open the .project and remove the first buildcommand javabuilder.This is done to ensure that only one |
| entry of javabuilder exists. <br>The correct order of builder and natures |
| are needed to ensure proper functionality.The final .project should look like this. |
| </p> |
| <img src="images/utilityproject.JPG"> |
| </li> |
| |
| <br> |
| <br> |
| <li> |
| Now create a <b>.wtpmodule</b> file in the bedrock project and put the following content. |
| <pre> |
| <?xml version="1.0" encoding="UTF-8"?> |
| <project-modules id="moduleCoreId"> |
| <wb-module deploy-name="bedrock.jar"> |
| <wb-module module-type-id="jst.utility"/> |
| <wb-resource deploy-path="/" source-path="/bedrock/src/java"/> |
| </wb-module> |
| |
| </project-modules> |
| |
| </pre> |
| |
| </li> |
| </ol> |
| </p></td></tr><tr><td colspan="2" align="left" bgcolor="#0080c0" valign="top"><b><font color="#ffffff" face="Arial,Helvetica">Bringing the project in the eclipse</font></b></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><p> |
| <ol> |
| <li> |
| <p> |
| From the Window->Preferences set the classpath variable MAVEN_REPO to point to the |
| repository of the maven. |
| </p> |
| <img src="images/DefiningMavenClassPath.JPG"> |
| </li> |
| <br> |
| <br> |
| |
| <li> |
| <p> |
| Import the projects using File->Import->Existing Project into workspace. |
| </p> |
| <img src="images/ImportProjectInEclipse.JPG"> |
| |
| </li> |
| <br> |
| <br> |
| <li> |
| <p> |
| Go to the csrweb, project Properties->Java Build Path->Source and add select Add Folder, point to the csrweb/LibraryContents<br> |
| </p> |
| |
| |
| </li> |
| |
| |
| </ol> |
| |
| </p></td></tr><tr><td colspan="2" align="left" bgcolor="#0080c0" valign="top"><b><font color="#ffffff" face="Arial,Helvetica">Running the Servlet in the Tomcat Server</font></b></td></tr><tr><td align="right" valign="top"> |
| |
| </td><td valign="top"><ol> |
| <li> |
| Open the J2EE perspective. |
| </li> |
| <br> |
| <br> |
| <li> |
| <p> |
| From the Window->Preferences, setup the Tomcat Server runtime |
| </p> |
| <img src="images/SetTomcatRuntime.JPG"> |
| </li> |
| |
| <br> |
| <br> |
| |
| <li> |
| Set up the server from the Servers view in the J2EE perspective |
| </li> |
| |
| <br> |
| <br> |
| |
| <li> |
| <p> |
| Set up the server in the web project |
| </p> |
| <img src="images/SettingServerInWebProject.JPG"> |
| </li> |
| |
| <br> |
| <br> |
| |
| <li> |
| Build the projects. |
| </li> |
| <br> |
| <br> |
| <li> |
| Run the web project csrweb by right clicking and choosing Run As->Run on Server |
| </li> |
| |
| </ol></td></tr></tbody></table></body></html> |