How to use an environment var in a property file

C

coltrane

Is it possible to use an environment variable in a property file?

I would like to set a property such as
dir.base=${environment.INSTALL_BASE}
where INSTALL_BASE is an env var.

then I would like to use ${dir.base} with a build.xml.

why do you ask would I want to do this???

I inherited a group of ant build scripts with hard coded paths in the
property files.
I would like to change them so the paths can be changed without
modifying the prop files.

I am very new to ant so forgive me if this is a simple question. and
yes I am reading the manual :)

thanks for your help

john
 
A

Ashish Pagey

You can pull in environment variables as properties into ant by using
the property tag:

<property environment="env"/>
<echo message="Installbase = ${env.INSTALL_BASE}"/>

-Ashish
 
C

coltrane

Thanks,

I cannot alter my ant files but I can alter my property files.What I
would like to do is use environment variables in the properties file.

This is a sample of what I have

property file
ant file
now what I want is to use an environment variable in the property file
and not touch the ant file

property file
ant file
I know this seems like extra work but as I said I can't change my ant
files and I still want to use environment files.

john
 
R

Raymond DeCampo

coltrane said:
Is it possible to use an environment variable in a property file?

I would like to set a property such as
dir.base=${environment.INSTALL_BASE}
where INSTALL_BASE is an env var.

then I would like to use ${dir.base} with a build.xml.

why do you ask would I want to do this???

I inherited a group of ant build scripts with hard coded paths in the
property files.
I would like to change them so the paths can be changed without
modifying the prop files.

I am very new to ant so forgive me if this is a simple question. and
yes I am reading the manual :)

You can override the values in the properties files by specifying them
as system properties. E.g. (assuming UNIX-style shell):

ant -Ddir.base=$INSTALL_BASE build

Do not forget to use quotes when appropriate.

HTH,
Ray
 
Joined
Jan 9, 2020
Messages
1
Reaction score
0
I am using the Base URL port in Environmental variable. How can i use this env variables in properties files?
export PORT_NUMBER=**** This is Environmental variable.
BaseUrl=http://localhost:(have to put the env variable) : how to get that env variables?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,083
Latest member
SylviaHarr

Latest Threads

Top