Here is how I have integrated my maven builds with myeclipse.
Install the maven integration for eclipse -
http://m2eclipse.codehaus.org/
Create a new Maven project (File -> New -> Project -> Maven -> Maven Project)
Set your packaging to war, and check off "/src/main/webapp" in the Project Layout section.
Once the project is created, right click, and go to Properties -> Java Build Path -> Libraries -> Add Library -> MyEclipse Libraries,
click Next and select J2EE 1.x or Java EE 5 libraries
Now, shutdown Eclipse and open up the .project file in your favourite text editor.
Now, I modified the .project file to add the MyEclipse natures back in. (Make sure to change the <name> node value to your project name)
<!-- START -->
| Code: |
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SampleWeb</name> <!-- this is your project name -->
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.genuitec.eclipse.ast.deploy.core.deploymentnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
</natures>
</projectDescription>
<!-- END --> |
Now, open up eclipse, right click on the project, and go to Properties -> MyEclipse -> Web -> ContextRoot and set your context root.
You'll notice that the Web-root folder is still set to /WebRoot so this has to be changed.
Go back to your filesystem, and open up your ".mymetadata" with your text editor. Change this:
<attributes>
<attribute name="webrootdir" value="/WebRoot" />
</attributes>
to this:
<attributes>
<attribute name="webrootdir" value="/src/main/webapp" />
</attributes>
Now, you have to restart MyEclipse again. Almost there, just a few more steps.
Create WEB-INF, WEB-INF/lib and WEB-INF/classes directories under /src/main/webapp and put in your web.xml file.
Right click on your project, go to Properties -> Java Build Path -> Source and set your output folder to /src/main/webapp/WEB-INF/classes
Now you're ready to go. You can deploy your web project to a server, and you can also do your maven builds.