wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Strange Ant Behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Strange Ant Behavior" Watch "Strange Ant Behavior" New topic
Author

Strange Ant Behavior

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I have an Ant task for WAR'ing up my web project. Here is the WAR task



The strange thing I just noticed is that if I look at the contents of the WAR file all the JAR files from my lib.dir are doubled. So I have 2 of every JAR file in the WAR file. Also, the j2ee.jar file is not being excluded. These issues don't cause problems when I deploy the WAR as Tomcat ignors the j2ee.jar file and as the contens are being extracted the JAR files just overright each other, but it is causing my WAR file to be twice as large in size. Plus it's just strange behavior.

I am running Ant 1.6.2 but it is also doing it withing IDEA which is running Ant version 1.5 or something of that nature. Anyone have any ideas?


GenRocket - Experts at Building Test Data
sanat
Ranch Hand

Joined: Dec 08, 2004
Posts: 111

Hi greg,

I don't know what's the problem with that script. But, I think this will work
--------------------------------------------------------------
<target name="build" depends="compile" >
<jar jarfile="something.war" basedir="${buildpath}"/>
</target>

<target name="compile" depends="init" >
compile all files to ${buildpath}\WEB-INF\classes
copy all .xml .tld files to ${buildpath}\WEB-INF
copy all .jar files to ${buildpath}\WEB-INF\lib
copy all .jsp .htm files to ${buildpath}
</target>

<target name="init" >
create all directory structures
</target>
---------------------------------------------------------------
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Is your webinf task grabbing the jars? I don't know the structure of your source directories.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Your lib folder isn't a sub folder of your ${jsp.dir} folder is it?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Paul Sturrock:
Your lib folder isn't a sub folder of your ${jsp.dir} folder is it?


Nope, sure isn't.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

I build my web projects as exploded WARs. Tomcat (among others) can use the exploded WAR for testing, then when I'm happy with it, I WAR up the exploded WAR. Like so:



The main benefits are that it saves a small amount of time when doing trivial experiments such as adjusting styles and that it makes the WAR function very straightforward.

The main downside is that I have to remember once I'm happy with my little tweaks to bounce them back to the source tree before I do the WAR build or watch them all get blown away (and it serves me right!).

And, of course, if you don't run a clean before building the WAR, you could get a mishmash of stuff some of which didn't come from the source tree. Fortunately I've got myself trained to always do "ant clean war".


Customer surveys are for companies who didn't pay proper attention to begin with.
Amber Vaidya
Ranch Hand

Joined: Oct 14, 2003
Posts: 42
I think Carol is right .. A typical directory structure would be

jsp
WEB-INF
lib
classes
web.xml

If this is similar to your directory structure then the jars are getting added twice because you have <lib> and <webinf> defined in your build.xml.

You may want to change your war task to


<war destfile="${build.dir}/${deploy.name}" webxml="WEB-INF/web.xml">
<fileset dir="${jsp.dir}" includes="**\*"/>
<metainf dir="META-INF"/>
<webinf dir="WEB-INF\">
<exclude name="web2.xml"/>
<exclude name="web.xml"/>
<exclude name="**\j2ee.jar"/>
</webinf>
</war>
[ January 14, 2005: Message edited by: Amber Vaidya ]
Amber Vaidya
Ranch Hand

Joined: Oct 14, 2003
Posts: 42
Oops , did not get the formatting right ..
I meant
jsp
WEB-INF
WEB-INF/classes
WEB-INF/lib
WEB-INF/web.xml
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Carol Enderlin:
Is your webinf task grabbing the jars? I don't know the structure of your source directories.


That was it. My structure pre-war is pretty much the same as post-war. So I removed the lib attrbite from the war task and all is well. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange Ant Behavior