Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a system property with ant

I have an ant script which has a taskdef and the task creates an https internet connection and somethin with that SSL stuff is wrong. Thus I want to set the system property javax.net.debug=all to get some more information.

In java I would do this using the -D option, but in ant this is used for ant properties which is not the same as a system property.

If this wouldn't be a taskdef but instead a java task, I could use the sysproperty property, but it is no java-task.

Googling for this is frustratingly complicated because ant properties and system properties in ant are so similar that most search results are about the other (or about the java-task).

Obviously I am not the only one with the problem, but other people's questions that I have found (like here) are unanswered or went for hack (like here).

like image 452
yankee Avatar asked Jan 15 '14 20:01

yankee


People also ask

Where are Ant properties set?

The home directory for Ant library files - typically ANT_HOME/lib folder. Ant also makes the system properties (Example: file. separator) available to the build file. In addition to the above, the user can define additional properties using the property element.


2 Answers

One way to set such a property is the ANT_OPTS system variable. You have to be very carefully to not simply skim over answers on google that state that options can be set that way, because it sounds so much like not what it does:

The documentation says:

ANT_OPTS - command-line arguments that should be passed to the JVM. For example, you can define system properties or set the maximum Java heap size here.

Who what have expected that? ANT_OPTS are options for the JVM and not for ant like the name suggests. The var which is used for ant options is called ANT_ARGS.

Now I can launch ant like this: ANT_OPTS="-Djavax.net.debug=all" ant myTarget and can see tons of log output.

(However this leaves the question open whether such a variable can be set using XML).

like image 157
yankee Avatar answered Oct 07 '22 07:10

yankee


You can declare system properties in the xml with <sysproperty key="key" value="value"/>.

http://www.java2s.com/Code/Java/Ant/SetsystempropertiesinAntbuildscript.htm

like image 40
Draukadin Avatar answered Oct 07 '22 08:10

Draukadin