Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Creating a war using ANT

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
Thanks in advance.
I am creating a jar file containing all the ejb classes using ANT.
I want to create a war as well as an ear file using an ANT.
Does any one know how it can be done.
I am using Orion1.5.2 as my application server.
Any help would be appreciated.
Thanks once again.
Preferably i would like to have a sample code.
My Web-App structure is as follows:--

Admin folder which contains JSP's
So other folders with third party tools in it
WEB-INF with web.xml and class files within this in the classes directory as per the hierarchy.
Also there are some javascript files in the base directory(Myproject-WebApp) along with Admin.

MyProject-WebApp
|
|-WEB-INF-|-classes
| |-web.xml
|-Admin-Alljsp
|-Documents- all documents
|-Tools- third party tools

etc this is how the hierarchy of my web application is.
Please if anyone has used ant to create a war file with such a hierarchy do inform me.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you use the war task?
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
I am new to Ant and am unable to understand the war task.It would be great if u could give me some sample code .
I was wondering how i would get all the files in my base folder to be in my war.
I want all the files which are there in the base folder to be in my war file.
Thanks for the reply
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just set the basedir attribute of the war task to be the base directory of your WebApp. Everything included in there will be added to your war.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paul I
Did the following in my Ant file but nothing was created can u help out
Here is the code

<?xml version="1.0"?>
<project name="myapp" basedir="." default="all">
<target name="init">
<property name="hello" value="world"/>
</target>
<target name="war" depends="init">
<war basedir="D:\projects\myproject\myproject-WebApp\" destfile="D:\projects\myproject\myproject-WebApp\myproject-WebApp.war">

</war>
</target>
<target name="all" depends="init" description="Build everything.">
<echo message="Application built. Hello ${hello}!"/>
</target>

</project>
src is the directory in which i have all my war files.
Thanks a lot Paul
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm. You sure that didn't fail? Granted I don't know which version of Ant you are using but I'm pretty sure you have to include the webxml attribute too.

Try it using a nested fileset element instead if you like, but basedir should work.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Ant 1.6.2 and it did not fail u dont need to include the web.xml
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<?xml version="1.0"?>
<project name="myapp" basedir="." default="all">
<target name="init">
<property name="hello" value="world"/>
</target>
<target name="war" depends="init">
<war basedir="D:\projects\myproject\myproject-WebApp\" destfile="D:\projects\myproject\myproject-WebApp\myproject-WebApp.war" webxml="D:\projects\myproject\myproject-WebApp\WEB-INF">
<fileset dir="D:\projects\myproject\myproject-WebApp\Admin">
<include name="**/*.*"/>
</fileset>


</war>
</target>
<target name="all" depends="init" description="Build everything.">
<echo message="Application built. Hello ${hello}!"/>
</target>

</project>

I made the above changes.
I get the message Application built HEllo.
But the war file is not created
 
Saloon Keeper
Posts: 28064
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ant -v" is your friend. It shows classpaths used and warnings that may be useful.

There are examples printed with the ant docs on the war task, y'know.

Web.xml can either be supplied as part of the source files to be warred or fed in via a task attribute. The task attribute is the preferred way - ant whines at you if you have a web.xml in the war source, but personally, I've found it more convenient to keep the whole thing together, so I keep hoping they'll eventually add the smarts to shut ant up.

Hoever, one case where getting the web.xml file from somewhere else makes sense is if ant is going to be customizing it as part of the build.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic