About     Search     Feed

Nilesh D Kapadia


Music     Twitter     Github

Migrating a web project from MyEclipse to Web Tools Project (WTP) 0.7

I recently migrated a web project that was using MyEclipse to using Eclipse WTP. It was actually quite simple. This assumes you have Eclipse 3.1 and WTP 0.7 installed (WTP also requires EMF and GEF to be installed). I started by creating a web project using WTP’s template (create a new “Dynamic Web Project”). Then I inspected the files it created and applied the differences to my existing MyEclipse-based project.

The web project I created with WTP was called “webproject”. So when you see “webproject” in the following files, that is the project name. The project layout looks like this:

/webproject
    /JavaSource     - source code directory
    /.deployables   - automatically generated files that are to be deployed
        /webproject
    /WebContent     - web content files
    .classpath      - Eclipse classpath config
    .project        - Eclipse project config
    .wtpmodules     - WTP config

In my MyEclipse-created project, “JavaSource” is “src”, and “WebContent” is “WebRoot”.

I opened up Navigator view to get a better of view of the files involved.

Lets look at the .classpath created, parts that need to change are bolded:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/j2sdk1.5-sun"/>
	<classpathentry kind="con"
path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5"/>
	<classpathentry output=".deployables/<b>webproject</b>/WEB-INF/classes" kind="src" path="<b>JavaSource</b>"/>
	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container/<b>webproject</b>"/>
	<classpathentry kind="output" path="bin"/>
</classpath>

Note the “bin” directory that is configured as an output directory. I left that as is. I replaced my entire .classpath file with this version. Most of my jar files are in WEB-INF/lib which WTP automatically adds to classpath, so the references to those jar files were not included in .classpath (you get an error if you do). There were some jar files that are not deployed that I included in .classpath, though.

I took the .project file from the WTP and replaced my MyEclipse .project with it, changing only the project name.

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name><b>webproject</b></name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.wst.common.modulecore.ComponentStructuralBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.wst.validation.validationbuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.wst.common.modulecore.DependencyGraphBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
	</natures>
</projectDescription>

Then I copied over the .wtpmodules file to the root of my project:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId">
<wb-module deploy-name="<b>webproject</b>">

<module-type module-type-id="jst.web">
<version>2.4</version>
<property name="context-root" value="<b>webproject</b>"/>
<property name="java-output-path" value="/bin/"/>
</module-type>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/<b>JavaSource</b>"/>
<wb-resource deploy-path="/" source-path="/<b>WebContent</b>"/>
</wb-module>
</project-modules>

I deleted the WebRoot/WEB-INF/classes directory that used to be an output directory. I closed and opened the project, did a Project->Clean which triggered a rebuild of the project. Then I switched to J2EE perspective and configured a Tomcat 5.5 instance for my project, started it up, browsed to URL that it normally is at, and everything worked. The .deployables directory was created automatically and I did not have to create it.

With the MyEclipse project, I was able to set it up such that I could work on the project in Eclipse without MyEclipse installed (just had to use Ant to build deployables). However, I’m not sure that it will work with this setup (Eclipse without WTP), since the classpath doesn’t have the jar files and they are probably not automatically included if WTP is not installed.

© 2013 Nilesh D Kapadia