wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes How do I set environment variables in Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How do I set environment variables in Ant" Watch "How do I set environment variables in Ant" New topic
Author

How do I set environment variables in Ant

Dar Var
Ranch Hand

Joined: Oct 12, 2004
Posts: 74
Hi

I want to be able to set Environment variables from within my Ant script depending on the OS.

I want to run the following from within Ant:


If the Ant script is run on Windows:

set MY_VARIABLE_NAME=C:/lOCATION

set PATH=C:\Location;%PATH%


If the Ant script is run on Unix:

MY_VARIABLE_NAME=/location
export VBROKER_ADM

PATH=/location:${PATH}
export PATH
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

Detecting the platform is easy - all of the JRE environment variables defined in java.System properties are available to Ant. I've run scripts that knew whether they were running Windows or Unix and, if Unix, whether Linux or Solaris.

Exporting out of Ant is a little more challenging.


Customer surveys are for companies who didn't pay proper attention to begin with.
Radu Codrin Leterna
Greenhorn

Joined: Jul 15, 2010
Posts: 5
Tim Holloway wrote:Exporting out of Ant is a little more challenging.


I know this topic was opened a long time ago... but can you detail the exporting of variables for Solaris out of Ant? Thanks!
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Radu and welcome to Javaranch!

Can I suggest you start a new thread with your exact issue? Thanks!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I set environment variables in Ant
 
Similar Threads
Running WebLogic sh script that sets environment variables from ANT
Working with Weblogic from ANT (start/stop/deploy/undeploy)
How to execute ant command from a java program using runtime.exec()?
problems with ant installation
Running .cmd file using "ant"