views:

597

answers:

3

I am developing a Tomcat app (actually it's a Red5 app, but this is effectively the same).

This contains the usual /WebContent/WEB-INF/lib folder, which is where I locate the various jars it uses.

Recently, I pulled a package out of my app project, and converted into a separate Jar project which was then released as open source (this resides in the same workspace).

What I want, is that when I build my Tomcat app, that Eclipse automatically pulls the latest version of the Jar I have built into its /WebContent/WEB-INF/lib folder.

This is the behaviour you get with .NET when you reference one project from another, and I guess this is why I was expecting to find some way of doing it.

At the moment, I have to manually copy/paste the Jar across each time I build it.

Of course, ideally when I build my Tomcat app it would automatically detect if the Jar project was up-to-date too, and build it if not.

Any suggestions most gratefully received.

A: 

You can configure Eclipse WTP to automatically assemble the web application right from Eclipse workspace without copying any jars. This way your changes in dependent project would be immediately reflected in the deployed web application.

As an alternative, you can use Ant or Maven script to copy jars where you want. With Maven you pretty much get it for free without writing any script or additional configuration.

Eugene Kuleshov
+1  A: 

I would go with build tools like:
1. Ant using File Tasks
2. Maven.

systempuntoout
+2  A: 

I have been trying to do this now - and I've almost got it working. I have 3 class libraries that I want in the WEB-INF/lib directory, so I created custom Ant builder rules for each of the class library eclipse projects to create the lib/classlib.jar file whenever the project sources change (search for 'Creating a project builder Ant buildfile' in the Eclipse help).

I then added each of these jar files (it's not sufficient to add just the project references) to the 'Java EE Module Dependencies' section of the web project.

When you export the web project they will appear in the .war file. I haven't found a way of getting them into it without having to export (I want to debug in-place rather than deploying the .war file).

I have to agree with systempuntoout that the most likely solution is to use an Ant builder.

Edit: Ant copy tasks work. Add a file called copylibs.xml to the root directory of the web project:

<?xml version="1.0" encoding="UTF-8"?>
<project name="copylibs" default="copylibs" basedir=".">

    <target name="copylibs" description="Copy dependent jar files">
        <copy file="../com-aaaa-util/lib/com-aaaa-util.jar" todir="webroot/WEB-INF/lib/" />
        <copy file="../com-aaaa-mnp/lib/com-aaaa-mnp.jar" todir="webroot/WEB-INF/lib/" />
        <copy file="../com-aaaa-bbbb/lib/com-aaaa-bbbb.jar" todir="webroot/WEB-INF/lib/" />
    </target>
</project>

Then add an Ant builder to do this during a build.

trojanfoe