I have two deployment configurations.
Each configuration store in its property file.
Dev configuration in dev.properties:
deploy.wowza.domain=DEV_IP_ADDRESS
Prod configuration in prod.properties:
deploy.wowza.domain=PROD_IP_ADDRESS
I have build.xml
<?xml version="1.0"?>
<project name="MAIN" default="dev" basedir=".">
<target name="dev">
<property file="${java.root.dir}/ant/dev.properties"/>
<echo>
DEV
${deploy.wowza.domain}
</echo>
<sleep seconds="1"/>
</target>
<target name="prod">
<property file="${java.root.dir}/ant/prod.properties"/>
<echo>
PROD
${deploy.wowza.domain}
</echo>
<antcall target="deploy"/>
</target>
</project>
If I run prod or dev task it show correct property value only from second run
D:\Dropbox\camwithme>ant prod
Buildfile: D:\Dropbox\camwithme\build.xml
prod:
[copy] Copying 1 file to D:\Dropbox\camwithme\wowza_cam\ant
[echo]
[echo] PROD
[echo] PROD_IP_ADDRESS
[echo]
BUILD SUCCESSFUL
Total time: 0 seconds
D:\Dropbox\camwithme>ant dev
Buildfile: D:\Dropbox\camwithme\build.xml
dev:
[copy] Copying 1 file to D:\Dropbox\camwithme\wowza_cam\ant
[echo]
[echo] DEV
[echo] PROD_IP_ADDRESS !!! Should be dev ip here !!!
[echo]
BUILD SUCCESSFUL
Total time: 0 seconds
D:\Dropbox\camwithme>ant prod
Buildfile: D:\Dropbox\camwithme\build.xml
prod:
[copy] Copying 1 file to D:\Dropbox\camwithme\wowza_cam\ant
[echo]
[echo] PROD
[echo] DEV_IP_ADDRESS
[echo]
Problem was because of another build.xml which load properties files before copy
Related
I have a Java application that I am packaging into a JAR. I created an Ant script to do that as I need to also add resources to the JAR (icons etc).
Now, I have libraries that I use in my project (Apache HttpClient and a JSON library). I also copy their contents into the JAR, as it is the simplest way.
My build file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar"
name="Create Runnable Jar">
<target name="create_run_jar">
<jar destfile="C:/Users/Pietu1998/Documents/Java/Whatever.jar"
filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class"
value="net.pietu1998.whatever" />
<attribute name="Class-Path" value="." />
</manifest>
<fileset dir="C:/Users/Pietu1998/Documents/Java/Whatever/bin"
includes="*.class" />
<fileset dir="C:/Users/Pietu1998/Documents/Java/Whatever/res" />
<zipfileset excludes="META-INF/**"
src="C:/Users/Pietu1998/Documents/Java/Whatever/lib/commons-codec-1.6.jar" />
<zipfileset excludes="META-INF/**"
src="C:/Users/Pietu1998/Documents/Java/Whatever/lib/commons-logging-1.1.3.jar" />
<!-- More (like 5) JARs -->
</jar>
</target>
</project>
However, the libraries (JARs) have their own META-INF folders, and they have a lot of stuff in them; files like LICENSE, CONDITIONS and also a folder for Maven called maven.
The project is for personal use, so I just want to get rid of the unnecessary stuff. I have tried some ways to exclude all of the META-INF stuff, but something is always left behind.
excludes="META-INF" leaves everything.
excludes="META-INF/**" leaves the maven folder.
**/excludes="META-INF/**", see above.
I believe I could use a lot of include-excludes or patternsets, but it would lead to a lot of repeating.
Is there a way (not for this specific case) to exclude a folder (META-INF here) and all its contents including subdirectories, and preferably with not too much repeating (for a lot of libraries)?
Using excludes="META-INF/**"" works for me (Ant 1.9.3, Windows 7, JDK 1.7.0_51)
Some test after downloading original commons-logging-1.1.3.jar from here :
<project>
<zipfileset excludes="META-INF/**" src="c:/area51/commons-logging-1.1.3.jar" id="foobar"/>
<!-- for output line by line -->
<pathconvert property="foo" refid="foobar">
<map from="c:/area51/commons-logging-1.1.3.jar:" to="${line.separator}"/>
</pathconvert>
<echo>${foo}</echo>
</project>
output contains only classfiles under org/apache/commons/logging/.. :
[echo] commons-logging-1.1.3.jar
[echo] org/apache/commons/logging/Log.class;
[echo] org/apache/commons/logging/LogConfigurationException.class;
[echo] org/apache/commons/logging/LogFactory$1.class;
[echo] org/apache/commons/logging/LogFactory$2.class;
[echo] org/apache/commons/logging/LogFactory$3.class;
[echo] org/apache/commons/logging/LogFactory$4.class;
[echo] org/apache/commons/logging/LogFactory$5.class;
[echo] org/apache/commons/logging/LogFactory$6.class;
[echo] org/apache/commons/logging/LogFactory.class;
[echo] org/apache/commons/logging/LogSource.class;
[echo] org/apache/commons/logging/impl/AvalonLogger.class;
[echo] org/apache/commons/logging/impl/Jdk13LumberjackLogger.class;
[echo] org/apache/commons/logging/impl/Jdk14Logger.class;
[echo] org/apache/commons/logging/impl/Log4JLogger.class;
[echo] org/apache/commons/logging/impl/LogFactoryImpl$1.class;
[echo] org/apache/commons/logging/impl/LogFactoryImpl$2.class;
[echo] org/apache/commons/logging/impl/LogFactoryImpl$3.class;
[echo] org/apache/commons/logging/impl/LogFactoryImpl.class;
[echo] org/apache/commons/logging/impl/LogKitLogger.class;
[echo] org/apache/commons/logging/impl/NoOpLog.class;
[echo] org/apache/commons/logging/impl/ServletContextCleaner.class;
[echo] org/apache/commons/logging/impl/SimpleLog$1.class;
[echo] org/apache/commons/logging/impl/SimpleLog.class;
[echo] org/apache/commons/logging/impl/WeakHashtable$1.class;
[echo] org/apache/commons/logging/impl/WeakHashtable$Entry.class;
[echo] org/apache/commons/logging/impl/WeakHashtable$Referenced.class;
[echo] org/apache/commons/logging/impl/WeakHashtable$WeakKey.class;
[echo] org/apache/commons/logging/impl/WeakHashtable.class
Maybe you forgot to set the update attribute from your jar task to true :
<jar destfile=".." update="true" ..>
to overwrite some already existing jarfile with the same name !?
I found a way to do it with the stars.
<zipfileset excludes="META-INF/**/*" src="C:\library.jar" />
This excludes the META-INF folder and all its contents.
* means it excludes all files inside a folder, and
foo/**/bar means it excludes bar in any level inside foo.
So, foo/**/* excludes every file on every level inside foo.
I have a property and target in my build.xml:
<property name="somedir" value="path/to/dir/${prop}"/>
<echo message="${prop}"/>
<target name="foo">
<echo message="Property: ${somedir}"/>
</target>
In the directory where build.xml is I run:
ant -Dprop="someVal" foo
This gets echoed:
[echo] someVal
[echo] Property: path/to/dir/
What happened to ${prop} when foo is called? How do I get the value to persist when foo is invoked?
Thanks in advance!
I can't reproduce your issue. What version of ANT are you using?
build.xml
<project name="demo" default="foo">
<property name="somedir" value="path/to/dir/${prop}"/>
<echo message="${prop}"/>
<target name="foo">
<echo message="Property: ${somedir}"/>
</target>
</project>
Run as follows:
$ ant -Dprop=hello
Buildfile: /home/me/tmp/build.xml
[echo] hello
foo:
[echo] Property: path/to/dir/hello
ANT version:
$ ant -version
Apache Ant(TM) version 1.9.0 compiled on March 5 2013
I'm using Ant version 1.8.4
I have this as my build.xml
<project>
<property name="somedir" value="path/to/dir/${prop}"/>
<echo message="${prop}"/>
<target name="foo">
<echo message="Property: ${somedir}"/>
</target>
</project>
I get this:
$ ant -Dprop=foo foo
Buildfile: /Users/david/build.xml
[echo] foo
foo:
[echo] Property: path/to/dir/foo
BUILD SUCCESSFUL
Total time: 0 seconds
I had to put <project> and </project> in the build.xml or else it wouldn't execute.
Is there something I'm missing? It seems to work fine.
I was trying to overwrite a pre-defined property that is immutable from the build.xml ...this is more along the lines of what I'm trying to do:
<project>
<property name="basedir" value="/usr/me/${prop}"/>
<echo message="${basedir}"/>
</project>
echos:
Buildfile: build.xml
[echo] /usr/me
BUILD SUCCESSFUL
Total time: 0 seconds
facepalm
Hi this is my code for copying a file from one location to another
<copy file="${MyParam}\${files.Sloc}\${files.names}" tofile="..\${cmdname}\${files.Tloc}\${files.names}"> </copy>
Although it is copying the file to its destination perfectly but thee problem is it is deleting the the previous directory structure that is if i have
D:/a/b/c/d/e and in e if i already have 1,2,3,4 as file now if i want to put another file into e,instead of placing it into e the above task first deletes D:/a/b/c/d/e and all files in e and creates new path as D:/a/b/c/d/e and places the new file there so i am losing everything out.is there anyway out please help.tried some things but they did not work our.
You are wrong.
I created this example:
<project default="run">
<target name="run">
<!-- create new directory with some files -->
<delete dir="a/b/c/d/e"/>
<mkdir dir="a/b/c/d/e"/>
<touch file="a/b/c/d/e/1"/>
<touch file="a/b/c/d/e/2"/>
<!-- list directory contents -->
<fileset id="e.contents.before" dir="a/b/c/d/e"/>
<property name="prop.e.contents.before" refid="e.contents.before"/>
<echo>Before copy: ${prop.e.contents.before}</echo>
<!-- copy some file to directory -->
<copy file="build.xml" tofile="a/b/c/d/e/build.xml"> </copy>
<!-- list directory contents -->
<fileset id="e.contents.after" dir="a/b/c/d/e"/>
<property name="prop.e.contents.after" refid="e.contents.after"/>
<echo>After copy: ${prop.e.contents.after}</echo>
</target>
The output is using Ant 1.8.2 on Linux:
Buildfile: /tmp/t/build.xml
run:
[delete] Deleting directory /tmp/t/a/b/c/d/e
[mkdir] Created dir: /tmp/t/a/b/c/d/e
[touch] Creating /tmp/t/a/b/c/d/e/1
[touch] Creating /tmp/t/a/b/c/d/e/2
[echo] Before copy: 1;2
[copy] Copying 1 file to /tmp/t/a/b/c/d/e
[echo] After copy: 1;2;build.xml
BUILD SUCCESSFUL
Total time: 0 seconds
i'm new to ant. Please highlight which goes wrong in my build.xml. Any help is appreciated. Thanks.
Problem: The folders i wanted to make kept created on the upper level of current directory.
ant version: 1.8.0
platform: LinuxMint 10.10
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.9) (6b20-1.9.9-0ubuntu1~10.10.2)
OpenJDK Server VM (build 19.0-b09, mixed mode)
build.xml:
<property name="prj.root" value="." />
<property name="build.dir" value="${prj.root}/build"/>
<property name="build.docs" value="${build.dir}/docs"/>
<property name="build.models" value="${build.dir}/models"/>
<property name="build.projects" value="${build.dir}/projects"/>
<property name="dist.dir" value="${prj.root}/dist"/>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<target name="init" depends="clean" description="initialization target">
<echo message=">> Build JAS ${jas.version} at ${prj.root}"/>
<echo message="build.dir = ${build.dir}" />
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.docs}" />
<mkdir dir="${build.models}" />
<mkdir dir="${build.projects}" />
<mkdir dir="${dist.dir}"/>
</target>
Execution + Output:
yamhon#yamhon-g410 ~/projects/JAS $ ant init
Buildfile: /home/yamhon/projects/JAS/build.xml
clean:
[delete] Deleting directory /home/yamhon/projects/build
[delete] Deleting directory /home/yamhon/projects/dist
init:
[echo] >> Build JAS ${jas.version} at .
[echo] build.dir = ./build
[mkdir] Created dir: /home/yamhon/projects/build
[mkdir] Created dir: /home/yamhon/projects/build/docs
[mkdir] Created dir: /home/yamhon/projects/build/models
[mkdir] Created dir: /home/yamhon/projects/build/projects
[mkdir] Created dir: /home/yamhon/projects/dist
BUILD SUCCESSFUL
Total time: 0 seconds
yamhon#yamhon-g410 ~/projects/JAS $
Two things you can try.
1) Resolve your relative '.' path by assigning it to a property with the location attribute.
<property name="my.path" location="."/>
<echo message="my.path = ${my.path}"/>
2) Use the build in basedir property which points to the directory of the build.xml file itself.
<echo message="basedir = ${basedir}"/>
This should get you going :)
I created a axis2 soap client project with unit tests using the following command:
wsdl2java -t -uri http://myDomain.tld/myService.svc?wsdl
I then ran ant and got build errors because it could not find junit methods such as fail(),assertNotNull(), etc. I realize I need the compiler to reference a junit jar. Looking in the build.xml I see the following:
<property name="classes" value="${build}/classes"/>
<property name="lib" value="${build}/lib"/>
So I place junit-4.8.2.jar in the build.lib subfolder. I still get the same errors. What else do I need to do to get ant to build my project?
Update:
I made the following changes to the build.xml:
Added the lib folder as a path with the id local.class.path
<path id="local.class.path">
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
Then I modified my init task to look for junit:
<available classpathref="local.class.path" property="junit.available" classname="junit.framework.TestCase"/>
<condition property="jars.ok">
<and>
<isset property="stax.available"/>
<isset property="axis2.available"/>
<isset property="junit.available"/>
</and>
</condition>
<!--Print out the availabilities-->
<echo message="Stax Availability= ${stax.available}"/>
<echo message="Axis2 Availability= ${axis2.available}"/>
<echo message="JUnit Availability= ${junit.available}"/>
And strangely the output is:
H:\Code\Java\test.axis2> ant pre.compile.test
Buildfile: H:\Code\Java\RiskTools.axis2\build.xml
init:
[mkdir] Created dir: H:\Code\Java\test.axis2\build
[mkdir] Created dir: H:\Code\Java\test.axis2\build\classes
[mkdir] Created dir: H:\Code\Java\test.axis2\build\lib
pre.compile.test:
[echo] Stax Availability= true
[echo] Axis2 Availability= true
[echo] JUnit Availability= ${junit.available}
BUILD SUCCESSFUL
Total time: 0 seconds
So it seems I am doing something wrong due to the line [echo] JUnit Availability= ${junit.available}
Apparently build/lib is the transient folder that gets blown away by ant clean. I made a folder called lib at the project root and then did the following to the build.xml.
In the root I added <property name="dep_libs" value="${project.base.dir}/lib"/>
I then change my path statement above to:
<path id="local.class.path">
<fileset dir="${dep_libs}">
<include name="*.jar"/>
</fileset>
</path>
Then everything worked.