如何更改ANT的JAVA_HOME? [英] How do I change the JAVA_HOME for ant?

查看:490
本文介绍了如何更改ANT的JAVA_HOME?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在没有root的类服务器上执行Java工作.每当我尝试使用ant进行编译时,它都指向错误的目录(/usr/tomcat而不是/usr/tomcat/jre).

I'm doing java work on a class server where I don't have root. Whenever I try to compile using ant, it points to the wrong directory (/usr/tomcat instead of /usr/tomcat/jre ).

在设置用户帐户时,我们被告知要做的一件事是将export JAVA_HOME=/usr/tomcat/jre添加到.bashrc文件中.我不知道这是否应该解决问题,但似乎没有.

One of the things we were told to do when setting up our user accounts was to add export JAVA_HOME=/usr/tomcat/jre to the .bashrc file. I don't know if that was supposed to take care of the problem but it doesn't seem to.

那么,如何更改ant的JAVA_HOME属性,但仅在运行ant时更改?

So, how can I change the JAVA_HOME property for ant but only for when I run ant?

echo $JAVA_HOME指向/usr/tomcat/jre echo $JAVA_HOME\bin指向/usr/tomcat/jrebin

问题是当我正常运行ant时出现此错误:

The problem is when I normally run ant I get this error:

Unable to locate tools.jar. Expected to find it in /usr/tomcat/lib/tools.jar
Buildfile: build.xml

compile:
    [javac] Compiling 1 source file to /home/ejm244/build/classes

BUILD FAILED
/home/ejm244/build.xml:9: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.

Perhaps JAVA_HOME does not point to the JDK

Total time: 0 seconds

推荐答案

您可以创建自己的脚本来运行ant,例如命名为ant.sh,例如:

You could create your own script for running ant, e.g. named ant.sh like:

#!/bin/sh
JAVA_HOME=</path/to/jdk>; export JAVA_HOME
ant $@

,然后运行您的脚本.

$ chmod 755 ant.sh
$./ant.sh clean compile

或您希望运行的任何蚂蚁目标

or whatever ant target you wish to run

这篇关于如何更改ANT的JAVA_HOME?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆