I am trying to get ANT and IVY to work behind proxy server.
SetProxy task works OK
<target name="proxy">
<property name="proxy.host" value="proxy.server.com" />
<property name="proxy.port" value="8080" />
<setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" />
</target>
But when I tried to use Environmental Variables
set ANT_OPTS="-Dhttp.proxyHost=proxy.server.com -Dhttp.proxyPort=8080"
Ivy cannot connect to repos and here is the Ant properties output for proxy
[echoproperties] http.proxyHost=proxy.server.com -Dhttp.proxyPort\=8080
When I tried "autoproxy" argument to no avail
ant -autoproxy deploy
Here is the out of ANT
C:\Workspace\DevProjects\fxin>ant -Dproxy.host=proxy.eur.xerox.com -Dproxy.port=8000 deploy
Buildfile: C:\Workspace\DevProjects\fxin\build.xml
load-properties:
[echo] Using properties file: build.properties
download-ivy:
[echoproperties] #Ant properties
[echoproperties] #Wed Dec 14 10:05:03 GMT 2011
[echoproperties] ant.core.lib=C\:\\Tools\\apache-ant-1.8.2\\lib\\ant.jar
[echoproperties] ant.file=C\:\\Workspace\\DevProjects\\fxin\\build.xml
[echoproperties] ant.file.fxin=C\:\\Workspace\\DevProjects\\fxin\\build.xml
[echoproperties] ant.file.type=file
[echoproperties] ant.file.type.fxin=file
[echoproperties] ant.home=C\:\\Tools\\apache-ant-1.8.2
[echoproperties] ant.java.version=1.7
[echoproperties] ant.library.dir=C\:\\Tools\\apache-ant-1.8.2\\lib
[echoproperties] ant.project.default-target=usage
[echoproperties] ant.project.invoked-targets=deploy
[echoproperties] ant.project.name=fxin
[echoproperties] ant.version=Apache Ant(TM) version 1.8.2 compiled on December 20 2010
[echoproperties] app.copyright=2011-2012
[echoproperties] app.name=fxin
[echoproperties] app.vendor=MyUser
[echoproperties] app.version=0.1
[echoproperties] appserver.home=C\:\\Users\\MyUser/bin/apache-tomcat-7.0.22
[echoproperties] appserver.lib=C\:\\Users\\MyUser/bin/apache-tomcat-7.0.22/lib
[echoproperties] awt.toolkit=sun.awt.windows.WToolkit
[echoproperties] basedir=C\:\\Workspace\\DevProjects\\fxin
[echoproperties] build.dir=war/WEB-INF/classes
[echoproperties] build.properties=build.properties
[echoproperties] db.driver=com.mysql.jdbc.Driver
[echoproperties] db.pw=demo
[echoproperties] db.url=jdbc\:mysql\://localhost\:3306/demo
[echoproperties] db.user=demo
[echoproperties] deploy.path=C\:\\Users\\MyUser/bin/apache-tomcat-7.0.22/webapps
[echoproperties] file.encoding=Cp1252
[echoproperties] file.encoding.pkg=sun.io
[echoproperties] file.separator=\\
[echoproperties] ivy.install.version=2.2.0-rc1
[echoproperties] ivy.jar.file=C\:\\Workspace\\DevProjects\\fxin\\lib\\tools\\ivy-2.2.0-rc1.jar
[echoproperties] ivy.retrieve.pattern=C\:\\Workspace\\DevProjects\\fxin\\lib/[conf]/[organisation]/[artifact]-[revision].[ext]
[echoproperties] ivy.settings.file=${res.ivy.dir}/ivysettings.xml
[echoproperties] java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
[echoproperties] java.awt.printerjob=sun.awt.windows.WPrinterJob
[echoproperties] java.class.path=C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-launcher.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-antlr.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-apache-bcel.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-apache-bsf.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-apache-log4j.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-apache-oro.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-apache-regexp.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-apache-resolver.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-apache-xalan2.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-commons-logging.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-commons-net.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-jai.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-javamail.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-jdepend.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-jmf.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-jsch.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-junit.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-junit4.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-launcher.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-netrexx.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-swing.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant-testutil.jar;C\:\\Tools\\apache-ant-1.8.2\\lib\\ant.jar;C\:\\Program Files\\Java\\jdk1.7.0\\lib\\tools.jar
[echoproperties] java.class.version=51.0
[echoproperties] java.endorsed.dirs=C\:\\Program Files\\Java\\jdk1.7.0\\jre\\lib\\endorsed
[echoproperties] java.ext.dirs=C\:\\Program Files\\Java\\jdk1.7.0\\jre\\lib\\ext;C\:\\Windows\\Sun\\Java\\lib\\ext
[echoproperties] java.home=C\:\\Program Files\\Java\\jdk1.7.0\\jre
[echoproperties] java.io.tmpdir=C\:\\TEMP\\
[echoproperties] java.library.path=C\:\\Program Files\\Java\\jdk1.7.0\\bin;C\:\\Windows\\Sun\\Java\\bin;C\:\\Windows\\system32;C\:\\Windows;C\:\\Program Files\\App\\App Feature Islands\\;C\:\\Windows\\system32;C\:\\Windows;C\:\\Windows\\System32\\Wbem;C\:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C\:\\Program Files\\Oracle\\instantclient_10_2;C\:\\Program Files\\Common Files\\Roxio Shared\\DLLShared\\;C\:\\Program Files\\Common Files\\Roxio Shared\\10.0\\DLLShared\\;C\:\\Tools\\cygwin\\bin;C\:\\Tools\\bin;C\:\\Program Files\\7-Zip;C\:\\Program Files\\ImageMagick-6.7.0-Q16;C\:\\Program Files\\Java\\jdk1.7.0\\bin;C\:\\Tools\\apache-ant-1.8.2\\bin;C\:\\Program Files\\TortoiseSVN\\bin;C\:\\Program Files\\MySQL\\MySQL Server 5.5\\bin;.
[echoproperties] java.runtime.name=Java(TM) SE Runtime Environment
[echoproperties] java.runtime.version=1.7.0-b147
[echoproperties] java.specification.name=Java Platform API Specification
[echoproperties] java.specification.vendor=Oracle Corporation
[echoproperties] java.specification.version=1.7
[echoproperties] java.vendor=Oracle Corporation
[echoproperties] java.vendor.url=http\://java.oracle.com/
[echoproperties] java.vendor.url.bug=http\://bugreport.sun.com/bugreport/
[echoproperties] java.version=1.7.0
[echoproperties] java.vm.info=mixed mode, sharing
[echoproperties] java.vm.name=Java HotSpot(TM) Client VM
[echoproperties] java.vm.specification.name=Java Virtual Machine Specification
[echoproperties] java.vm.specification.vendor=Oracle Corporation
[echoproperties] java.vm.specification.version=1.7
[echoproperties] java.vm.vendor=Oracle Corporation
[echoproperties] java.vm.version=21.0-b17
[echoproperties] lib.build.dir=C\:\\Workspace\\DevProjects\\fxin\\lib\\compile
[echoproperties] lib.dir=C\:\\Workspace\\DevProjects\\fxin\\lib
[echoproperties] lib.runtime.dir=C\:\\Workspace\\DevProjects\\fxin\\lib\\runtime
[echoproperties] lib.test.dir=C\:\\Workspace\\DevProjects\\fxin\\lib\\test
[echoproperties] lib.tools.dir=C\:\\Workspace\\DevProjects\\fxin\\lib\\tools
[echoproperties] line.separator=\r\n
[echoproperties] os.arch=x86
[echoproperties] os.name=Windows 7
[echoproperties] os.version=6.1
[echoproperties] path.separator=;
[echoproperties] proxy.host=proxy.server.com
[echoproperties] proxy.port=8000
[echoproperties] report.dir=C\:\\Workspace\\DevProjects\\fxin\\report
[echoproperties] report.ivy.dir=C\:\\Workspace\\DevProjects\\fxin\\report\\ivy
[echoproperties] report.javac.dir=C\:\\Workspace\\DevProjects\\fxin\\report\\javac
[echoproperties] res.dir=res
[echoproperties] res.ivy.dir=C\:\\Workspace\\DevProjects\\fxin
[echoproperties] source.encoding=UTF-8
[echoproperties] source.version=1.5
[echoproperties] src.dir=src
[echoproperties] sun.arch.data.model=32
[echoproperties] sun.boot.class.path=C\:\\Program Files\\Java\\jdk1.7.0\\jre\\lib\\resources.jar;C\:\\Program Files\\Java\\jdk1.7.0\\jre\\lib\\rt.jar;C\:\\Program Files\\Java\\jdk1.7.0\\jre\\lib\\sunrsasign.jar;C\:\\Program Files\\Java\\jdk1.7.0\\jre\\lib\\jsse.jar;C\:\\Program Files\\Java\\jdk1.7.0\\jre\\lib\\jce.jar;C\:\\Program Files\\Java\\jdk1.7.0\\jre\\lib\\charsets.jar;C\:\\Program Files\\Java\\jdk1.7.0\\jre\\classes
[echoproperties] sun.boot.library.path=C\:\\Program Files\\Java\\jdk1.7.0\\jre\\bin
[echoproperties] sun.cpu.endian=little
[echoproperties] sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
[echoproperties] sun.desktop=windows
[echoproperties] sun.io.unicode.encoding=UnicodeLittle
[echoproperties] sun.java.command=org.apache.tools.ant.launch.Launcher -Dproxy.host proxy.server.com -Dproxy.port 8000 deploy
[echoproperties] sun.java.launcher=SUN_STANDARD
[echoproperties] sun.jnu.encoding=Cp1252
[echoproperties] sun.management.compiler=HotSpot Client Compiler
[echoproperties] sun.os.patch.level=
[echoproperties] test.dir=test
[echoproperties] tomcat.manager.password=s3cret
[echoproperties] tomcat.manager.url=http\://localhost\:8080/manager
[echoproperties] tomcat.manager.username=tomcat
[echoproperties] user.country=US
[echoproperties] user.country.format=GB
[echoproperties] user.dir=C\:\\Workspace\\DevProjects\\fxin
[echoproperties] user.home=C\:\\Users\\MyUser
[echoproperties] user.language=en
[echoproperties] user.name=MyUser
[echoproperties] user.script=
[echoproperties] user.timezone=
[echoproperties] user.variant=
[echoproperties] web.dir=war
[echoproperties] web.lib=war/WEB-INF/lib
[echo] installing ivy...
[get] Getting: http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0-rc1/ivy-2.2.0-rc1.jar
[get] To: C:\Workspace\DevProjects\fxin\lib\tools\ivy-2.2.0-rc1.jar
[get] Error getting http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0-rc1/ivy-2.2.0-rc1.jar to C:\Workspace\DevProjects\fxin\lib\tools\ivy-2.2.0-rc1.jar
Any Ideas?
I have finally got it to work by setting the Env. variable without the surrounding double qoutes
set ANT_OPTS=-Dhttp.proxyHost=proxy.eur.xerox.com -Dhttp.proxyPort=8000
For some reason with double quotes or specifying on the command didn't work. Proxy setting had to be in environmental variable with quotes.
To add further;
according to http://ant.apache.org/manual/install.html#proxy
specifying proxy settings on command wouldn't work, as they would be standard ANT properties not JVM options
Thanks for your time
You are setting wrong properties.
Try
-Dproxy.host=proxy.server.com -Dproxy.port=8080
Related
I am trying to read a property file (xml) in ANT.
Following is the sample data.
<WebLogicDomain>
<Domain>MyDomain</Domain>
<Environment>DEV</Environment>
<Servers>
<Server id = '1'>
<Host>Host1</Host>
<Port>14100</Port>
<AliasName>adminserver</AliasName>
<IsAdmin>true</IsAdmin>
<AdminServerHost>adminHost</AdminServerHost>
<ClusterName>#NA</ClusterName>
<MinHeap>512MB</MinHeap>
<MaxHeap>2048MB</MaxHeap>
</Server>
<Server id = '2'>
<Host>Host2</Host>
<Port>14110</Port>
<AliasName>managedserver01</AliasName>
<IsAdmin>false</IsAdmin>
<AdminServerHost>adminHost</AdminServerHost>
<ClusterName>Cluster1</ClusterName>
<MinHeap>512MB</MinHeap>
<MaxHeap>2048MB</MaxHeap>
</Server>
</Servers>
</WebLogicDomain>
With this property file I can easily access Domain & Environment properties but How do I get specific Server Properties?
If I need to get ${WebLogicDomain.Servers.Server[1].Host} i.e Host present at index 1, how do I get that?
Follwoing doesn't work as expected.
<project name="SampleProject">
<xmlproperty file="buildproperties.xml" />
<target name="init">
<echo> ******** XML property file has been loaded. ******** </echo>
<echo> Domain name is : ${WebLogicDomain.Domain}</echo>
<echo> Environment is : ${WebLogicDomain.Environment}</echo>
<echo> First Server Details are : ${WebLogicDomain.Servers.Server[1].Host} </echo>
</target>
</project>
When I run the init target, I get following error.
init:
[echo] ******** XML property file has been loaded. ********
[echo] Domain name is : MyDomain
[echo] Environment is : DEV
[echo] First Server Details are : ${WebLogicDomain.Servers.Server[1].Host}
When Ant's xmlproperty task finds multiple elements with the same name in the same location, it saves them to a single property as a comma-delimited list. Try using the xmlproperty task to view all the properties that your build has loaded, along with corresponding nested elements. DOM information, unfortunately, is mostly lost. You can try to rely on the order in which the properties are listed, using regex to extract the relevant information, but this will almost certainly be awkward and unreliable.
<xmlproperty file="weblogic.xml" />
<echoproperties prefix="WebLogicDomain" />
Output:
[echoproperties] #Ant properties
[echoproperties] #Thu Feb 15 16:42:17 PST 2018
[echoproperties] WebLogicDomain.Domain=MyDomain
[echoproperties] WebLogicDomain.Environment=DEV
[echoproperties] WebLogicDomain.Servers.Server(id)=1,2
[echoproperties] WebLogicDomain.Servers.Server.AdminServerHost=adminHost,adminHost
[echoproperties] WebLogicDomain.Servers.Server.AliasName=adminserver,managedserver01
[echoproperties] WebLogicDomain.Servers.Server.ClusterName=\#NA,Cluster1
[echoproperties] WebLogicDomain.Servers.Server.Host=Host1,Host2
[echoproperties] WebLogicDomain.Servers.Server.IsAdmin=true,false
[echoproperties] WebLogicDomain.Servers.Server.MaxHeap=2048MB,2048MB
[echoproperties] WebLogicDomain.Servers.Server.MinHeap=512MB,512MB
[echoproperties] WebLogicDomain.Servers.Server.Port=14100,14110
If you really need to do XML parsing that is more complicated than basic string retrieval, there's a 3rd party plugin called XmlTask that can accomplish this. http://www.oopsconsultancy.com/software/xmltask/
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath location="lib/xmltask.jar"/>
</taskdef>
<target name="default">
<xmltask source="weblogic.xml">
<copy path="WebLogicDomain/Servers/Server[#id='1']/Host/text()" property="server.1.host"/>
</xmltask>
<echo message="${server.1.host}" />
</target>
Output:
[echo] Host1
How to invoke same target by passing different values to the parameter?
I wanted to invoke target using antcall.
Based on some falg i wanted to invoke a target by passing different values to the parameter using param.
Don't use antcall, better use macrodef (introduced with Ant 1.6) instead !!
I won't go into details, just search the web for 'antcall vs. macrodef' and similar..
See also Writing Better Ant Scripts: Techniques, Patterns and Antipatterns
Some snippet :
<project xmlns:if="ant:if">
<macrodef name="foobar">
<attribute name="foo"/>
<attribute name="verbose"/>
<sequential>
<echo>#{foo}</echo>
<echoproperties prefix="ant" if:true="#{verbose}"/>
</sequential>
</macrodef>
<!-- use foobar macrodef with different parameters (attribute values) -->
<foobar verbose="yes" foo="1. yada,yada"/>
<foobar verbose="no" foo="2. blabla.."/>
</project>
output :
[echo] 1. yada,yada
[echoproperties] #Ant properties
[echoproperties] #Thu Sep 18 09:31:05 CEST 2014
[echoproperties] ant.core.lib=C\:\\ant194\\lib\\ant.jar
[echoproperties] ant.file=C\:\\area51\\ant\\tryme.xml
[echoproperties] ant.home=C\:\\ant194
[echoproperties] ant.java.version=1.7
[echoproperties] ant.library.dir=C\:\\ant194\\lib
[echoproperties] ant.version=Apache Ant(TM) version 1.9.4 compiled on April 29 2014
[echo] 2. blabla..
I have a properties file that I want to echo out the values
<HSMKeys>
<Key domain="default" value="TestA" />
<Key domain="fixed" value="TestB" />
</HSMKeys>
as
[echo] domain=default value=TestA
[echo] domain=fixed value=TestB
How can I do this, ie loop over the properties file and have the two variables that would be in the echo.
I have tried the following
<for list="${HSMKeys.Key.domain}" param="domain">
<sequential>
<echo>domain=#{domain}</echo>
</sequential>
</for>
ie I can only get at one attribute value at a time, not both at once.
Thanks.
As #thekbb has stated this is not a properties file, however, ANT supports the parsing of XML files as properties.
<project name="demo" default="print">
<xmlproperty file="properties.xml"/>
<target name="print">
<echoproperties prefix="HSMKeys."/>
</target>
</project>
Produces the following output:
print:
[echoproperties] #Ant properties
[echoproperties] #Tue Dec 03 23:44:14 GMT 2013
[echoproperties] HSMKeys.Key=,
[echoproperties] HSMKeys.Key(domain)=default,fixed
[echoproperties] HSMKeys.Key(value)=TestA,TestB
May not be exactly what you need but has the advantage of not requiring additional jars like Ant-contrib.
That's not a properties file. Properties files are key/value pairs. How are you populating list?
a property file ant will understand will look like:
domain.default=TestA
domain.fixed=testB
I recommend avoiding ant-contrib at all costs... what are you really trying to do?
you could simply use echoproperties
<project name="test" default="echo" basedir=".">
<property file="build.properties" />
<target name="echo" >
<echoproperties prefix="domain."/>
</target>
</project>
I have a property file containing keys and values as shown below:
TC_name1=true
Tc_name2=false
I need an Ant script to iterate through this property file and get only the keys with value equal to true.
Also I want to know whether it is possible to use an .ini file as our property file.
Please help me out with this as I googled, but was not able to find the solution.
build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project default="load">
<target name="load">
<!-- load the properties as plain text into a property -->
<loadfile property="trueProps" srcfile="load.properties">
<!-- only load affirmative values of properties -->
<filterchain>
<linecontainsregexp>
<regexp pattern="=\s*(true|yes|on)\s*$" />
</linecontainsregexp>
</filterchain>
<!-- prefix for easy retrieval -->
<filterchain>
<prefixlines prefix="testing." />
</filterchain>
</loadfile>
<!-- print the property contents -->
<echo taskname="trueProps">${trueProps}</echo>
<!-- extract the keys -->
<loadresource property="trueKeys" >
<string>${trueProps}</string>
<filterchain>
<replaceregex pattern="=\s*(true|yes|on)\s*$" replace="" />
</filterchain>
</loadresource>
<!-- print the keys -->
<echo taskname="trueKeys">${trueKeys}</echo>
<!-- load the contents of the variable as ant properties -->
<loadproperties>
<string>${trueProps}</string>
</loadproperties>
<!-- confirm the properties are loaded as expected -->
<echoproperties prefix="testing." />
</target>
</project>
load.properties:
prop1=false
some_other=true
also_true=yes
yet_another=on
not_this=no
TC_name1=true
Tc_name2=false
some_other_match =yes
not_a_yes= false
output:
Buildfile: build.xml
load:
[trueProps] testing.some_other=true
[trueProps] testing.also_true=yes
[trueProps] testing.yet_another=on
[trueProps] testing.TC_name1=true
[trueProps] testing.some_other_match =yes
[trueKeys] testing.some_other
[trueKeys] testing.also_true
[trueKeys] testing.yet_another
[trueKeys] testing.TC_name1
[trueKeys] testing.some_other_match
[echoproperties] #Ant properties
[echoproperties] #Wed May 29 10:57:26 EDT 2013
[echoproperties] testing.TC_name1=true
[echoproperties] testing.also_true=yes
[echoproperties] testing.some_other=true
[echoproperties] testing.some_other_match=yes
[echoproperties] testing.yet_another=on
BUILD SUCCESSFUL
Total time: 0 seconds
I want to know if this is possible:
Referring to files in zipfileset which may or may no exist due to build output
how can i handle this in zipfileset
Any ideas?
Thanks
Regards
Karthik
Include/exclude works for files, but not directories.
At least as of 1.8.x (which is what I'm using, didn't check 1.6), you can use:
<zipfileset dir="something" prefix="" erroronmissingdir="false">
to not yield that error.
The "erroronmissingdir" attribute allows a fix for this condition.
I don't see any problem with it.
Here is an example zip (jar) file:
$ jar tvf src.zip
0 Wed Nov 30 11:54:38 GMT 2011 META-INF/
62 Wed Nov 30 11:54:38 GMT 2011 META-INF/MANIFEST.MF
0 Wed Nov 30 11:53:28 GMT 2011 src/
0 Wed Nov 30 11:57:14 GMT 2011 src/a/
0 Wed Nov 30 11:53:38 GMT 2011 src/a/exists.txt
0 Wed Nov 30 11:57:14 GMT 2011 src/a/other.txt
Here is an example build file to test the behaviour of zipfileset for existent and non-existent files:
<project default="test">
<target name="test">
<pathconvert property="found">
<zipfileset src="src.zip">
<include name="src/a/not-exists.txt"/>
<include name="src/a/exists.txt"/>
</zipfileset>
</pathconvert>
<echo message="found: ${found}"/>
<mkdir dir="extract"/>
<copy todir="extract">
<zipfileset src="src.zip">
<include name="src/a/not-exists.txt"/>
<include name="src/a/exists.txt"/>
</zipfileset>
</copy>
</target>
</project>
Here is the output from this sample:
$ ant
Buildfile: C:\tmp\ant\build.xml
test:
[echo] found: C:\tmp\ant\src.zip:src/a/exists.txt
[mkdir] Created dir: C:\tmp\ant\extract
[copy] Copying 1 resource to C:\tmp\ant\extract
BUILD SUCCESSFUL
Total time: 0 seconds
There are no errors from the attempt to access non-existent files.
And here is the result in the dir files were copied to from the zip:
$ find extract/
extract/
extract/src
extract/src/a
extract/src/a/exists.txt