Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange Ant Behavior

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sanat
Ranch Hand
Posts: 111
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your webinf task grabbing the jars? I don't know the structure of your source directories.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your lib folder isn't a sub folder of your ${jsp.dir} folder is it?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Amber Vaidya
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic