I want to avoid being prompted for the password during a build, but I also want to keep it out of the files so I was trying to set it up so I can type this into command prompt:
SET password=pword
ant release
My ant.properties file looks like this:
key.store=../KeyStore/Project.keystore
key.alias=project
key.store.password=${env.password}
key.alias.password=${env.password}
In my build.xml I have the line:
<property environment="env" />
As far as I understand from here that's all I need, but it doesn't work, says the password is wrong (note I have tripple check it's right, and hard coded it in the ant.properties to test).
It was simply the order of the lines in the build.xml.
The line with the env must be above the ant.properties line.
<property environment="env" />
<property file="ant.properties" />
Related
I use Launch4j and will use a property ${dist} in its configuration.
It works when the task and it argument directly are in the build.xml file:
<project ...>
<property name="dist" location="/temp/dist" />
<launch4j>
<config headerType="gui" outfile="${dist}/myprogram.exe"
dontWrapJar="false" jarPath="${dist}/myprogram.jar">
...
</config>
</launch4j>
</project>
Launch4j can however use its own xml-configuration file, with <launch4jConfig> as root element:
in ant.xml:
<launch4j configFile="my_launch4j_config.xml" />
in my_launch4j_config.xml:
<launch4jConfig>
<headerType>gui</headerType>
<outfile>${dist}/myprogram.exe</outfile>
<dontWrapJar>false</dontWrapJar>
<jar>${dist}/myprogram.jar</jar>
...
</launch4jConfig>
In this case, ${dist} is not expanded, nor %dist% or everything I tried... Does a solution exist to use properties in an launch4j config file?
The code of launch4j did not accept such replacements of parameters, but I could change this behaviour (modifications to net.sf.launch4j.config.ConfigPersister). I check it in the Sourceforge project when I have enough time for it.
I have defined a macro in ant script which takes host as parameter:
<macrodef name="upload">
<attribute name="host"/>
<sequential>
<echo>Uploading source code to #{host}...</echo>
<scp trust="true"
file="package/code.zip"
todir="${webserver.username}##{host}:${webserver.upload_dir}"
keyfile="${webserver.keyfile}"
passphrase="" />
</sequential>
</macrodef>
Problem is I can't figure out how to use #{host} in todir string as it already has a '#' character between username and host.
Per : https://ant.apache.org/manual/Tasks/macrodef.html ,
The escape sequence ## is used to escape #.
This allows #{x} to be placed in the text without substitution of x by using ##{x}.
So try with adding additional '#' prior to getting value of host attribute.
Also you could try setting <property name="token" value="#"/> and use it withing todir with ${token} to see if that helps
Hi all please give a look to this code
in my properties file i have
win-x86.pc-shared-location=E:\Ant_Scripts
Now below i am trying to call PrintInstallerName_build from my build.xml,while as PrintInstallerName_build is in test.xml. In build.xml file,${platform.id} has value=win-x86 in the calling target and in called target param1 also has value=win-x86
<target name="PrintInstallerName" >
<echo>PlatForm.Id====>${platform.id}</echo>
<ant antfile="test.xml" target="PrintInstallerName_build">
<property name="param1" value="${platform.id}"/>
</ant>
<target name="PrintInstallerName_build" >
<echo>${param1.pc-shared-location}</echo><!--${param1.pc-shared-location}-->
<echo>${param1}.pc-shared-location}</echo><!--win-x86.pc-shared-location-->
<echo>${win-x86.pc-shared-location}</echo><!--E:\\Ant_Scripts-->
</target>
as you can see only the last statement gives correct output but it is hardcoded,i want to use param1 and the output should be E:\\Ant_Scripts i tried to use $ and # but none works,may be i am doing wrong somewhere can someone help please,i am struck and tomorrow is its DOD.
See Nesting of Braces in the Properties page of the Ant Manual.
In its default configuration Ant will not try to balance braces in
property expansions, it will only consume the text up to the first
closing brace when creating a property name. I.e. when expanding
something like ${a${b}} it will be translated into two parts:
the expansion of property a${b - likely nothing useful.
the literal text } resulting from the second closing brace
This means you can't use easily expand properties whose names are
given by properties, but there are some workarounds for older versions
of Ant. With Ant 1.8.0 and the the props Antlib you can configure Ant
to use the NestedPropertyExpander defined there if you need such a
feature.
You can use <propertycopy> to make it happen.
Consider that you need to have the property value of ${propA${propB}}
Use ant tag of propertycopy as follows:
<propertycopy property="myproperty" from="PropA.${PropB}"/>
<echo >${myproperty}</echo>
This will echo the value of ${propA${propB}}
<target name="PrintInstallerName_process" >
<echo>${param1}</echo><!--win-x86-->
<macrodef name="testing">
<attribute name="v" default="NOT SET"/>
<element name="some-tasks" optional="yes"/>
<sequential>
<echo>Source Dir of ${param1}: ${#{v}}</echo><!-- Dir of Win-x86:E:\Ant_Scripts-->
<some-tasks/>
</sequential>
</macrodef>
<testing v="${param1}.pc-shared-location">
<some-tasks>
</some-tasks>
</testing>
</target>
this is the way it works and for me it works fine anyways #sudocode your tip took me there so thank you very much
I have thousands of properties in my property file and I want to change only one property like the following.
<propertyfile file="${mypropetyfile}">
<entry key="jndiname" value="java:comp/env/wm/default"/>
</propertyfile>
but in the property file I am getting the property value with an extra \:
jndiname=java\:comp/env/wm/default
I tried with the <echo> task but it removes other properties. I also tried by concatenation like following in this case also I am getting extra \
<propertyfile file="${mypropetyfile}">
<entry key="jndiname" default="" operation="+" value="java:comp/env/wm/default"/>
</propertyfile>
The \ before the : is an escape character. Although it's not necessary here because the : is not part of the key, but is part of the value, it doesn't hurt either. Using Properties.load() to load this properties file will unescape the :. You should not care about the escape.
Just ran into the same problem changing a property file read by Websphere 6.1 & ended up having to do this workaround:
<property name="jndi.example" value="java:comp/env/example" />
<propertyfile file="jdbc.properties">
<entry key="datasource.example.jndi" operation="=" value="#EXAMPLE"/>
</propertyfile>
<!-- set tokens to property values because ant wants to 'escape the colon' -->
<replace file="jdbc.properties" token="#EXAMPLE" value="${jndi.example}" />
The 'best answer' isn't really addressing the problem. The Properties.load() is not the answer as in the case (which is highly likely), you won't control the 'other side' that will be consuming the properties file.
It doesn't appear you can set the <propertyfile/> to not do this. Seems like a bug to me.
The <replace> suggestion seems like the best course of action imo.
I found that when I used the echo task the entry came out as expected\desired in the file.
However, if I ran the propertyfile task afterwards to populate the same file with some values, it escaped all the colons in the file.
To get around this I simply ensured I ran the propertyfile task first, then the echo.
I have an ant file that does the following:
<property file="project.properties" description="Project configuration properties"/>
<property file="build-defaults.properties" description="default build configuration."/>
<property file="build.properties" description="local build configuration overrides"/>
I want to have defaults set in build-defaults.properties (which is checked in to SCM) but allow developers to override values in a local build.properties so that they can work with local paths.
The problem is, it doesn't seem to be working; I've set this up, created an override in build.properties, but the value of my path remains the one set in build-defaults.properties. How do I accomplish this?
The initial problem with your set up is that you've got build.properties and build-defaults.properties reversed.
Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it.
So the way you want this set up is:
<property file="build.properties" description="local build configuration overrides"/>
<property file="project.properties" description="Project configuration properties"/>
<property file="build-defaults.properties" description="default build configuration."/>
This way:
Anything set at the command line takes precedence over build.properties
Anything set in build.properties overrides other values
etc. on down the line.
Actually ant properties may be overriden. See the documentation of the property task:
Normally property values can not be changed, once a property is set,
most tasks will not allow its value to be modified.
One of the tasks that are able to override the property value is script. Also any custom task may use this backdoor. Other proposals are in question Ant loadfile override property. This is against the spirit of ant and usually unnecessary. But it's good to know that, because I just had an opposite problem: why the property value changed although it is immutable.
Here is a sample target that uses script task to change the value of a property. It shows the basic methods to work with properties. All methods are described in Ant Api which is not available online. You need to download the Ant Manual. In its api directory there is the api documentation.
<target name="t1">
<property name="a" value="one" />
<script language="javascript">
sProp = project.getProperty("a");
sProp = sProp.replace("e", "ly");
project.setProperty("a", sProp);
project.setNewProperty("a", "new value");
</script>
<property name="a" value="two" />
<echo>a=${a}</echo>
</target>
How to easily setup the script task? Making the script task running with beanshell language is a bit tricky and non-trivial, but it's explained in this answer. However as Rebse noted, using javascript language is supported out of the box in jdk 6.
Ant property can't be overwritten unless using macro and javascript plug-in to do:
Step 1: define a macro function to overwrite property
<!--overwrite property's value-->
<macrodef name="set" >
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<script language="javascript">
<![CDATA[
project.setProperty("#{name}", "#{value}");
]]>
</script>
</sequential>
</macrodef>
Step 2: use the macro in the ant xml
<set
name="your_target_property"
value="your_value" or "${another_property}"
</set>