Converting a Java project to a Dynamic Web project in Eclipse

 

Unfortunatelly there is no easy way to convert project type in Eclipse. In order to do this conversion we need to get to the guts of the eclipse project settings the ".project" file.

 

The .project file is located in the root directory of your project and may look some thing like this:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>warewolf</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.maven.ide.eclipse.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.maven.ide.eclipse.maven2Nature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

 

The above example represents a maven project that has just been created from scratch

As you can see the Eclipse identifies the type of the project by analysing the "natures" of the project that are specified in the .project file. So in order to tell eclipse that we would like to enable dynamic web project features we need to add additional natures to our file. Please note that it is best to close eclipse while you are performing the modification. And here is the modified file that includes the changes:

 

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>warewolf</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.maven.ide.eclipse.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>

        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>

        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>

    </buildSpec>
    <natures>
        <nature>org.maven.ide.eclipse.maven2Nature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>

        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>

        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>

    </natures>
</projectDescription>

 

Once the modifications are done you can open the eclipse and open the properties of the project by right clicking on the project root and selecting properties (or use a shortcut ALT+Enter).

Then you need to select the Project Facets configurations and check the Dynamic Web Module (choose the servlet api version as you require)

Eclipse facets properties

 

And you're done :-)

This page was last updated on: 07/08/2009 06:27