Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   problem creating WAR file with ant (http://www.velocityreviews.com/forums/t954602-problem-creating-war-file-with-ant.html)

Laura Schmidt 11-18-2012 04:53 PM

problem creating WAR file with ant
 
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

Arne Vajh°j 11-18-2012 05:01 PM

Re: problem creating WAR file with ant
 
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



Laura Schmidt 11-19-2012 03:21 AM

Re: problem creating WAR file with ant
 
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

Lew 11-19-2012 04:18 AM

Re: problem creating WAR file with ant
 
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

Arne Vajh°j 11-19-2012 02:41 PM

Re: problem creating WAR file with ant
 
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




All times are GMT. The time now is 02:42 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.