Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [wtp-dev] WTP modules, facets and extensability


We do that quite often to divide the development of a Web application to multiple projects (A web project + Multiple Utility). This was one of the use-cases that triggered the flexible project structures work in WTP.  It is in the API, so aşready covered. I do not think you need a facet for it. but it would be neat to have a facet that simplifies that setup described below.

Some parts of the process I will describe can be done using the wizards but others need some "one-time" manual configuration.  Complete wizardry is not in place, but this is a scenario that is very useful for teams develloping large Web applications. We have described this procedure in our upcoming WTP book - Java Web Development using WTP, which I co-authored with Arthur Ryman and Lawrence Mandel.

Here is what you can do:

1) Create a Web  Project  - WP.
2) Create a Java Utility Project - JUP.
3) Create a folder under the Java Utility Project named WebContent (or any other thing)
4) Change the J2EE module dependencies for the WP so that it depends on JUP.  At the time of deployment this will create a JAR and package it with the WP under the WEB-INF/lib.

This is all standard and you can repeat it for as many utility projects as you want.  Now the FUN part !

5) JUP is not really a Java Utility but a sub-web-application! It can have web content, it should know about the common web libraries, tlds etc.  It needs to know about the "Web Application library" of the WP.  So go to Java Build Path of JUP and add WP as a "Web Application Library", you will see that it is available as a dropdown option.

6) step 5 solves the sharing of the web libraries, we need to do reverse also.  If you develope some web content in addition to java in the JUP, these will have to be packaged with the WP.  Create a folder within the JUP project, name it "WebContent" or smt similar.

7) You can probably skip this step but I find it useful.  Create a symbolic link to the WebContent folder in JUP in the WP project folder (e.g. call it JUPWebContent). 

8)  This step is the heart of the flexible project structures.  Open the WTP module definitions file that you will find under the .settings folder (WP/.settings/org.eclipse.wst.common.component) of the Web project, modify the mappings like the following to add JUP WebContent to the deployment by adding the line

<wb-resource source-path="/JUPWebContent" deploy-path="/"/>

to the file.  The final result should look like:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="WP">
        <wb-resource source-path="/WebContent" deploy-path="/"/>
        <wb-resource source-path="/JUPWebContent" deploy-path="/"/>
        <wb-resource source-path="/src" deploy-path="/WEB-INF/classes"/>
        <dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/JUP/JUP">
        <property name="context-root" value="WP"/>
        <property name="java-output-path" value="build/classes"/>

That is it!

Hope it helps,  I would like to hear your comments


I'm trying to create a specialized type of a jst.utility module that any
dynamic web project can depend on. It's "specialized" because I want to
define additional publishing steps.

Usually jst.utility modules are published as Jars in the WEB-INF/lib
directory. I want to extend this behavior and also publish some
additional resources into the web root directory (eg. HTML files,
_javascript_ files, etc.).

However, it looks like the whole facets and modules framework was not
designed with such extensibility in mind. All the server implementation
which do the actual publishing hard code the publishing process. Is
there a generic solution to this problem or is this a complete new
feature request for the API?

CU, Gunnar


Naci Dai,

eteration a.s. 
itu teknokent ari-1 25
Maslak, Istanbul 34469

+90 (533) 580 2393 (cell)
+90 (212) 328 0825 (phone)
+90 (212) 328 0521 (fax)

Back to the top