如何在ubuntu中设置环境变量ANT_OPTS?

时间:2014-04-07 06:47:48

标签: java eclipse ubuntu liferay liferay-ide

在Ubuntu 10.0.4中设置liferay环境时,我在.bashrc文件中设置了这样的环境变量

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

我在终端上测试了这样的环境变量:

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

在为liferay运行build-themes时遇到以下错误:

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

2 个答案:

答案 0 :(得分:3)

我在.bashrc中看到了几个问题

  • /usr/bin/java/jdk1.7.0_51/bin看起来并不正确。 /usr/bin用于可执行文件。通常这类似于/usr/lib/java/.../usr/lib/jvm/...
  • JAVA_HOMEANT_HOME
  • 相同
  • @fge已指向set path=$path $ANT_HOME/bin。这将是PATH=$PATH:$ANT_HOME/bin

最后是错误消息,唯一的区别是512m vs 256m

更新

我只是查看了我的系统(Ubuntu 12.04),ant位于/usr/share/ant下方,所以对于ant来说这将是

ANT_HOME=/usr/share/ant

虽然,如果您通过包管理安装了ant包,则不需要设置ANT_HOMEPATH

更新

如果你从eclipse运行ant,可能不会加载.bashrc,除非你从命令行启动eclipse。 .bashrc仅为交互式bash shell加载,请参阅Bash Startup Files

答案 1 :(得分:3)

最后我已经修改了这样的环境变量:

# Java environment variables

JAVA_HOME=/opt/java/jdk1.7.0_51
export JAVA_HOME

PATH=$JAVA_HOME/bin:$PATH
export PATH


ANT_HOME=/opt/apache-ant-1.7.1
export ANT_HOME

PATH=$ANT_HOME/bin:$PATH 
export PATH 

ANT_OPTS="-Xmx1024m -XX:MaxPermSize=512m"
export ANT_OPTS

在.bashrc文件中,我已经在终端中打开了eclipse ..现在它正常工作..