problem creating WAR file with ant

L

Laura Schmidt

Hello,

I have a web project W, which uses a java library L. This "usage" is
based on the eclipse confguration: I just told eclipse that W uses L.
Since then, the java compiler finds the source files of L when compiling W.

I delpoy the web project as a war file using ant:

<target name="buildwar">
<war basedir="war" destfile="myproject.war"
webxml="war/WEB-INF/web.xml">
</war>

When I deploy this war file to a tomcat server, the class files of L are
missing.

I tried to resolve this by adding a symbolic link pointing from
$W/WEB-INF/classes to $L/classes. This worked, but after some rebuilds
this link was deleted somehow. I assume that the contents of
$w/WEB-INF/classes is deleted sometimes by some build procedures.

Then, I tried to add the dependency in the ant file:

<target name="buildwar">
<war ...>
<fileset dir="path/to/L/classes"/>
</war>
</target>

But this also didn't work.

Within the produced war file, the class files of L were in the root
directory. I believe that the class files should be placed into the
WEB-INF/classes directory of the war file.

However, this problem cannot be new and there must be a standard way to
do it. I would be glad if someone can tell me how to do it right.

Thanks
Laura
 
A

Arne Vajhøj

I have a web project W, which uses a java library L. This "usage" is
based on the eclipse confguration: I just told eclipse that W uses L.
Since then, the java compiler finds the source files of L when compiling W.

I delpoy the web project as a war file using ant:

<target name="buildwar">
<war basedir="war" destfile="myproject.war"
webxml="war/WEB-INF/web.xml">
</war>

When I deploy this war file to a tomcat server, the class files of L are
missing.

I tried to resolve this by adding a symbolic link pointing from
$W/WEB-INF/classes to $L/classes. This worked, but after some rebuilds
this link was deleted somehow. I assume that the contents of
$w/WEB-INF/classes is deleted sometimes by some build procedures.

Then, I tried to add the dependency in the ant file:

<target name="buildwar">
<war ...>
<fileset dir="path/to/L/classes"/>
</war>
</target>

But this also didn't work.

Within the produced war file, the class files of L were in the root
directory. I believe that the class files should be placed into the
WEB-INF/classes directory of the war file.

However, this problem cannot be new and there must be a standard way to
do it. I would be glad if someone can tell me how to do it right.

The war task has a nested lib element.

There is an example at the bottom at:
http://ant.apache.org/manual/Tasks/war.html

Use that!

Arne
 
L

Laura Schmidt

On 11/18/2012 11:53 AM, Laura Schmidt wrote:

Hi Arne!
The war task has a nested lib element.

There is an example at the bottom at:
http://ant.apache.org/manual/Tasks/war.html

Use that!

If I use that I''ll have to create a jar file for the library every time
I make changes to it. Instead of the lib element I used a symbolic link
in the WEB-INF/lib directory of the project pointing to the library's
jar file. This is the way I always did it.

But now I find it useful to avoid this step by directly including the
library's class files, which are located under $L/classes. What about this?

If including the class files directly, where in the war file do they belong?

Thanks!
Laura
 
L

Lew

Neither is correct.

The JAR of L should be in the lib/ subdirectory within the WAR.

RTFM.

There is, and the documentation tells you what it is.

As indeed, a WAR has a nested lib/ subdirectory. As per the docs.
If I use that I''ll have to create a jar [sic] file for the library every time
I make changes to it.

Yeah, so? Why wouldn't you? You say that like it's an argument against
doing things the right way.
Instead of the lib element I used a symbolic link
in the WEB-INF/lib directory of the project pointing to the library's
jar file. This is the way I always did it.

It's the wrong way.
But now I find it useful to avoid this step by directly including the
library's class files, which are located under $L/classes. What about this?

Terrible idea, and the wrong way to do it.
If including the class files directly, where in the war [sic]
file do they belong?

They don't.

Libraries belong in JAR files.

RTFM.

Really. You're doing it all ass-backwards.

http://www.oracle.com/technetwork/java/javaee/documentation/tutorials-137605.html
 
A

Arne Vajhøj

If I use that I''ll have to create a jar file for the library every time
I make changes to it.

You want to do that anyway.

You could even say that if it is not in a jar then it is not a
library.
Instead of the lib element I used a symbolic link
in the WEB-INF/lib directory of the project pointing to the library's
jar file. This is the way I always did it.

That makes the war file tied to your PC.

Not a good way.
But now I find it useful to avoid this step by directly including the
library's class files, which are located under $L/classes. What about this?

Extracting class files out of libraries jar files is not good as
it complicates updating and will confuse people working with it.
If including the class files directly, where in the war file do they
belong?

The war task also has a nested classes element.

It is all in the docs.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top