${env.JAVA_HOME} not found - Ant

后端 未结 2 1808
孤城傲影
孤城傲影 2021-02-19 06:08

In my build.xml file, I have these lines:



2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 06:50

    You can usually find on your system (if you're Unix) where the actual ant command lives by doing either which ant or type ant. If you look at that location, you will usually see that it's a link to the actual ant command under the $ANT_HOME directory.

    Take a look at this script. Much of it is just trying to determine exactly where $ANT_HOME and $JAVA_HOME reside if these are not set by default in the environment.

    What you don't see in the ant shell script is:

     EXPORT JAVA_HOME
    

    So, even though $JAVA_HOME is set inside the ant script, it is never exported into the environment (unless someone has modified the ant shell script. If an environment variable is not exported, it is unavailable to child processes -- like thejavachild process running yourant` process.

    Thus, if you are on a machine where $JAVA_HOME isn't set before ant is executed, it won't be available in your build script.

    However, both Ant and Java (because Ant is a Java process) setup a whole slew of default properties that you can use. When Ant executes it sets it's own built in properties that include things like ${ant.home}. And, when Java is executed, Java also sets up a complete list of Java Properties like ${java.home}.

    So, if you really need to know where your JAVA_HOME directory is located, use the property ${java.home} and not depend upon the environment variable $JAVA_HOME.

    If you'd like to get a list of these properties, run the following Ant build file:

    
        
    
    

提交回复
热议问题