Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > problem creating WAR file with ant

Reply
Thread Tools

problem creating WAR file with ant

 
 
Laura Schmidt
Guest
Posts: n/a
 
      11-18-2012
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
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      11-18-2012
On 11/18/2012 11:53 AM, Laura Schmidt wrote:
> 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


 
Reply With Quote
 
 
 
 
Laura Schmidt
Guest
Posts: n/a
 
      11-19-2012
On 11/18/2012 06:01 PM, Arne Vajhøj wrote:
> On 11/18/2012 11:53 AM, Laura Schmidt wrote:


Hi Arne!

>> 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!


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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      11-19-2012
Laura Schmidt wrote:
>>> 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.


Neither is correct.

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

RTFM.

>>> 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.


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

>> The war task has a nested lib element.


As indeed, a WAR has a nested lib/ subdirectory. As per the docs.

>> 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 [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/ja...ls-137605.html

--
Lew
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      11-19-2012
On 11/18/2012 10:21 PM, Laura Schmidt wrote:
> On 11/18/2012 06:01 PM, Arne Vajhøj wrote:
>> On 11/18/2012 11:53 AM, Laura Schmidt wrote:
>>> 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!

>
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The War Criminal about to Start another War Ctrl€/Alt€/Del€ Computer Support 30 11-30-2010 02:45 PM
ant doubt using war task harryos Java 0 12-03-2008 08:15 AM
Problem creating war file with warbler Thomas Kellerer Ruby 8 04-03-2008 10:51 AM
Updating single file in war file with Ant ddog Java 1 08-12-2007 03:39 AM
ant mixes up file hierarchy within war file Werner Butscher Java 2 08-02-2004 10:08 AM



Advertisments