aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes basic question: abt properties file and build xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "basic question: abt properties file and build xml" Watch "basic question: abt properties file and build xml" New topic
Author

basic question: abt properties file and build xml

Gerome Kawa
Ranch Hand

Joined: Dec 05, 2002
Posts: 61
Hi
I have to create a folder (named XYZ) in a servlet but i need to pass on the name when I build the web app . I want to give the folder-name in a properties file, and replace the folder-name in the servlet when am building the app through build.xml

Question:
What to do in build.xml ?
What to do in the servlet ?
How to access the properties file from the build.xml?

Any help will be deeply appreciated.

Thanks
Kawa
anna pillutla
Ranch Hand

Joined: Aug 27, 2004
Posts: 32

What to do in build.xml ?

put something like this in your build.xml

<target name="replace-tokens">
<replace dir="<<path of the properties file>>"
replacefilterfile="<<name of the properties file>>"/>
</target>


What to do in the servlet ?


In your servlet put the name of the folder as "@replacename@"


And in your .properties file say

@replacename@ = webapps // webapps will be the folder name which gets replaced with @replacename@ while building.

Hope this helps you.

Anna.
Gerome Kawa
Ranch Hand

Joined: Dec 05, 2002
Posts: 61
Thanks anna !
Gerome Kawa
Ranch Hand

Joined: Dec 05, 2002
Posts: 61
I am having some problems as follows:

When am trying to execute the command
c:\hubtransmission>build all

am getting the following error

C:\hubtransmission>build all
-------------Hubtransmission 1.0 Build System-------------
Using Ant at c:\hubtransmission\buildtools\ant1.6.1

Buildfile: build.xml

init:

replace-tokens:

BUILD FAILED
C:\hubtransmission\build.xml:38: Either the file or the dir attribute must be specified


It seems the ant.properties cannot be identitfied but I cannot make out why ?
Anyone spot the mistake ?
**************************************************************
folder structure
**************************************************************
hubtransmission
--build(build.xml, ant.properties, build.bat)
----deploymentdescriptors
----ear
----src
----war
--buildtools
----ant1.6.1
--lib
--src
----descriptors
----java
----web
**************************************************************
build.xml
**************************************************************
<project name="Hubtransmission Emulator" default="all" basedir=".">

<target name="init">

<!--
<property file="ant.properties"/>
-->
<property name="fs" value="${file.separator}"/>
<property environment="env"/>

<property name="dirs.base" value="${basedir}"/>
<property name="classdir" value="${dirs.base}/build/src"/>
<property name="src" value="${dirs.base}/src"/>
<property name="web" value="${dirs.base}/web"/>
<property name="deploymentdescription" value="${dirs.base}/build/deploymentdescriptors"/>

<property name="ant.properties" value="ant.properties" />

<property name="warFile" value="hubtransmission.war"/>
<property name="earFile" value="hubtransmission.ear"/>


<property name="earDir" value="${dirs.base}/build/ear"/>
<property name="warDir" value="${dirs.base}/build/war"/>


<!-- Create Web-inf and classes directories -->
<mkdir dir="${warDir}/WEB-INF"/>
<mkdir dir="${warDir}/WEB-INF/classes"/>

<!-- Create Meta-inf and classes directories -->
<mkdir dir="${earDir}/META-INF"/>

</target>

<!-- Replace tokens-->
<target name="replace-tokens">
<replace replacefilterfile="ant.properties"/>
</target>

<!-- Main target -->
<target name="all" depends="init,replace-tokens,build,buildWar,buildEar"/>


<!-- Compile Java Files and store in /build/src directory -->
<target name="build" >
<javac srcdir="${src}" destdir="${classdir}" debug="true" includes="**/*.java" />
</target>

<!-- Create the War File -->
<target name="buildWar" depends="init">

<copy todir="${warDir}/WEB-INF/classes">
<fileset dir="${classdir}" includes="**/*.class" />
</copy>

<copy todir="${warDir}/WEB-INF">
<fileset dir="${deploymentdescription}" includes="web.xml" />
</copy>

<copy todir="${warDir}">
<fileset dir="${web}" includes="**/*.*" />
</copy>

<!-- Create war file and place in ear directory -->
<jar jarfile="${earDir}/${warFile}" basedir="${warDir}" />

</target>


<!-- Create the War File -->
<target name="buildEar" depends="init">
<copy todir="${earDir}/META-INF">
<fileset dir="${deploymentdescription}" includes="application.xml" />
</copy>

<!-- Create ear file and place in ear directory -->
<jar jarfile="${dirs.base}/${earFile}" basedir="${earDir}" />
</target>
</project>

**************************************************************
anna pillutla
Ranch Hand

Joined: Aug 27, 2004
Posts: 32
May be you can try by specifying "dir" attribute of replace tag, which takes the path of the properties file.

I mean..

<target name="replace-tokens">
<replace dir="<<path>>" replacefilterfile="ant.properties"/>
</target>

Hope this helps.

Anna.
Gerome Kawa
Ranch Hand

Joined: Dec 05, 2002
Posts: 61
Anna
The ant.properties file is in the same folder as build.xml so what do i put in the dir attribute ?

Thanks
Kawa
anna pillutla
Ranch Hand

Joined: Aug 27, 2004
Posts: 32
Hi Kawa,

If ant.properties file is in ${dirs.base} you can give this as value for dir attribute.

Basically, what I mean to say is to give full path till parent directory of ant.properties file. Like if ant.properties file is in c:\AntTest. Then dir will have value something like this:

<target name="replace-tokens">
<replace dir="c:\AntTest" replacefilterfile="ant.properties"/>
</target>

Hope this helps.

Anna.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: basic question: abt properties file and build xml
 
Similar Threads
Buildfile: build.xml does not exist! Build failed
Creating Workspace from an Old One in Eclipse
taskdef
the system cannot find the path specified (again)
ant not deploying on Tomcat 7