2015-09-27 49 views
0

即使通过Windows安装程序安装了Java和/或ant,仍需要set your environment variables。确保你将java连接到JDK而不是JRE,作为一个新手,我猜测你编译自己的代码时,应该总是使用JDK,因为它具有所有你需要的工具。当导致makefile改变目录并在新目录中运行ant时出错“JAVA_HOME未正确定义”

原帖:

这一切发生在Windows上。我打电话给make。它从svn中检出一个“code”文件夹,存放到makefile所在的目录中。在“code”内部,是一个build.xml。我希望我的makefile转换到该目录,然后在其上运行ant。我得到的错误在我的命令提示符:

C:\Users\Ryan\Desktop\maketest>make 
svn co (address removed) 
Checked out revision 107. 
cd code; ant clean compile jar run 
uname: not found 
basename: not found 
dirname: not found 
which: not found 
Error: JAVA_HOME is not defined correctly. 
    We cannot execute java 
make: *** [runant] Error 1 

我曾经到过这里http://sunsite.ualberta.ca/Documentation/Gnu/make-3.79/html_chapter/make_5.html#SEC46,似乎这应该是做,能够在我的makefile:

runant: 
    cd code; ant clean compile jar run 

,因为这将在打开命令subshel​​l,但它也会在该子shell中运行ant。

这一切工作正常,如果我手动更改到代码文件夹并运行蚂蚁。当我尝试从一个makefile中完成所有操作时,我只会得到这个JAVA_HOME没有正确定义的错误。

生成文件:

commands = checkoutcode checkoutdocs runant 

svnCode = https://version-control.adelaide.edu.au/svn/SEPADL15S2UG7/code/ 
svnDocs = https://version-control.adelaide.edu.au/svn/SEPADL15S2UG7/updateDocs 

ifdef version 
REVISION = -r$(version) 
endif 

all: full 

full: checkoutcode checkoutdocs runant 

# ensure you use a single tab for the commands being run under that name 
checkoutcode: 
    svn co $(svnCode) $(REVISION) 

checkoutdocs: 
    svn co $(svnDocs) $(REVISION) 

#change directory into the code folder and compile the code 
runant: 
    cd code; ant clean compile jar run 

的build.xml:

<project> 
    <!-- add some property names to be referenced later. first one is lib folder to hold all libraries --> 
    <property name="lib.dir"  value="lib"/> 
    <!-- images directory used to compile with the images and also add them to the jar --> 
    <property name="src/images.dir"  value="images"/> 

    <!-- ensure the classpath can see all classes in the lib folder by adding **/*.jar --> 
    <path id="classpath"> 
     <fileset dir="${lib.dir}" includes="**/*.jar"/> 
    </path> 

    <!-- "Target" attribute is what we will write as a parameter to ant in the command prompt or terminal --> 
    <!-- eg. "ant clean" will run the commands inside the target tags, which is just to delete the directory 
      "build" --> 
    <target name="clean"> 
     <delete dir="build"/> 
     <echo message="Cleaned "/> 
    </target> 

    <!-- compile command. creates a directory for the classes to be stored in, instead of the root folder 
     and then compiles everything in the src folder, using the classpath properties we set earlier --> 
    <target name="compile"> 
     <mkdir dir="build/classes"/> 
     <javac includeantruntime="false" srcdir="src" destdir="build/classes" classpathref="classpath"/> 
     <echo message="Compiled "/> 
    </target> 

    <!-- jar command. this creates an executable jar file called Robot.jar which can run the program in full. 
     it uses the images and it uses the lejos libraries and embeds them into the jar --> 
    <target name="jar"> 
     <jar destfile="Robot.jar" basedir="build/classes"> 
      <fileset dir="src/images" /> 
      <manifest> 
       <attribute name="Main-Class" value="Main"/> 
      </manifest> 
      <!-- this line adds everything in the lib folder to the classes being added to the jar, 
      ie. the lejos classes ev3 and pc --> 
      <zipgroupfileset dir="${lib.dir}" includes="**/*.jar" /> 
     </jar> 
      <echo message="Created JAR "/> 
    </target> 

    <!-- run command. runs the program. Running the program in the command prompt or terminal is good 
     because it allows you to see any exceptions as they happen, rather than hiding them in eclipse --> 
    <target name="run"> 
     <java jar="Robot.jar" fork="true"/> 
      <echo message="Run "/> 
    </target> 

</project> 

我在没有执行的任何额外的配置运行此不同的机器上必需的,将无法确认的Java的位置在这些机器上 - 我将得到的唯一保证是安装了Java并且环境变量正常工作。

+0

终端在键入时打印什么:'echo%JAVA_HOME%' –

+0

ok - 我将JAVA_HOME添加为用户环境变量。回声JAVA_HOME打印路径jre1.8.0_51 现在它的工作原理,但我得到以下 - uname:找不到 基地名称:找不到 错误:无法找到或加载主类org.apache.tools.ant.launch。发射器 –

+0

好的,还得添加ANT_HOME环境变量。现在它说它不能在java home lib文件中找到tools.jar。所以,我的朋友说我需要一个JDK而不是JRE。即时下载它,但是,当然,我们都不知道运行环境和开发工具包在使用蚂蚁方面的区别 –

回答

0

只是回答让你标记为已解决。

即使您已经使用oracle安装程序安装了Java,您仍然需要创建环境变量。

0

即使您通过Windows安装程序安装了Java和/或ant,您仍需要set your environment variables.确保您将java链接到JDK而不是JRE,但作为新手,我的猜测是当您编译时您自己的代码应始终使用JDK,因为它具有您需要的所有工具。