Fixing WebContent Problems in Eclipse

By default, a ‘Dynamic Web Application’ project in Eclipse will put the non-code resources (pages, WEB-INF, META-INF, etc.) in a folder under the project called WebContent.

Exporting .war files or publishing to a server works just fine, as Eclipse knows what WebContent represents, and what should be done in order to deploy it.

The trouble comes when you want to create a new WebContent folder (which you might want to do if you’re going to start using Maven as a build tool on an existing project – Eclipse no longer knows where the resources are and your exports stop working.

If you end up in this situation, you can fix it if you know where in the Eclipse config the declaration of WebContent is. Problematic if you deleted the old WebContent folder already as the declaration gets tidied up (by my experience anyway).

The fix is very simple. Say you want to declare /src/main/webapp as your new WebContent folder
1. Open the .settings folder under the project (if you can’t see it in the Project Explorer view, use the Navigator view)

2. Open the file org.eclipse.wst.common.component

3. In the wb-module tag, add a new entry as follows:

<wb-resource deploy-path="/" source-path="/src/main/webapp"/>

Here’s an example of a basic file to put that into context.

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="MyProject">
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
        <wb-resource deploy-path="/" source-path="/src/main/webapp"/>
        <property name="context-root" value="MyProject"/>
        <property name="java-output-path" value="/MyProject/build/classes"/>
    </wb-module>
</project-modules>

The views expressed here are the personal views of the author.

Posted on April 10, 2010 at 6:35 pm by Paul Brabban · Permalink
In: Development

One Response

Subscribe to comments via RSS

  1. Written by brooke
    on June 20, 2013 at 3:01 am
    Permalink

    I believe you can (and should) do this through the GUI –

    Your Project > Properties > Deployment Assembly

    And to have say ‘WebContent’ in your project root folder and thus avoiding the navigation through all the directories just to open your jsp/jsf files is easy too.

    New > Folder, name ‘WebContent’ (or whatever) & add an alias to the directory.

Subscribe to comments via RSS

Leave a Reply