how to set the environment variable ANT_OPTS in ubuntu?

ASR picture ASR · Apr 7, 2014 · Viewed 13.6k times · Source

while setting up liferay environment in Ubuntu 10.0.4, i have set the environment variables like this in .bashrc file

PATH=/usr/bin/java/jdk1.7.0_51/bin:$PATH
export PATH

JAVA_HOME=/usr/bin/java/jdk1.7.0_51
export JAVA_HOME

PATH=/usr/bin/ant/bin:$PATH
export PATH

ANT_HOME=/usr/bin/ant

export ANT_HOME

ANT_OPTS="-Xmx1024m -XX:MaxPermSize=256m"

export ANT_OPTS

set path=$path $ANT_HOME/bin

i have tested environment variables like this in my terminal:

sudheer@VY-B3:~$ echo $PATH
/usr/bin/ant/bin:/usr/bin/java/jdk1.7.0_51/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
sudheer@VY-B3:~$ echo $JAVA_HOME
/usr/bin/java/jdk1.7.0_51
sudheer@VY-B3:~$ echo $ANT_HOME
/usr/bin/ant
sudheer@VY-B3:~$ echo $ANT_OPTS
-Xmx1024m -XX:MaxPermSize=256m

while running build-themes for liferay getting following error:

Buildfile: /home/sudheer/Desktop/Life-ray/Liferay_workspace/portal/portal-web/build.xml

BUILD FAILED
/home/sudheer/Desktop/Life-ray/Liferay_workspace/portal/portal-web/build.xml:4: The following error occurred while executing this line:
/home/sudheer/Desktop/Life-ray/Liferay_workspace/portal/build-common-web.xml:4: The following error occurred while executing this line:
/home/sudheer/Desktop/Life-ray/Liferay_workspace/portal/build-common.xml:393: .

Please set the environment variable ANT_OPTS to the recommended value of
"-Xmx1024m -XX:MaxPermSize=512m".

Total time: 2 seconds

Answer

Olaf Dietsche picture Olaf Dietsche · Apr 7, 2014

I see several problems in your .bashrc

  • /usr/bin/java/jdk1.7.0_51/bin doesn't look right. /usr/bin is for executable files. Usually this is something like /usr/lib/java/... or /usr/lib/jvm/...
  • same for JAVA_HOME and ANT_HOME
  • @fge already pointed to set path=$path $ANT_HOME/bin. This would be rather PATH=$PATH:$ANT_HOME/bin

And finally the error message, the only difference is just 512m vs 256m.

Update:

I just looked in my system (Ubuntu 12.04), ant is located below /usr/share/ant, so for ant this would be

ANT_HOME=/usr/share/ant

Although, if you installed the ant package via package management, there should be no need to set ANT_HOME and PATH.

Update:

If you run ant from eclipse, .bashrc might not be loaded, unless you start eclipse from the command line. .bashrc is only loaded for an interactive bash shell, see Bash Startup Files