How to change JAVA.HOME for Eclipse/ANT

前端 未结 10 1872
星月不相逢
星月不相逢 2020-12-04 17:36

I am trying to sign a jar file using an ANT script. I know this has to be pointed at the JDK directory for jarsigner.exe to run, but when I echo java.home it re

相关标签:
10条回答
  • 2020-12-04 18:10

    In Eclipse the Ant java.home variable is not based on the Windows JAVA_HOME environment variable. Instead it is set to the home directory of the project's JRE.

    To change the default JRE (e.g. change it to a JDK) you can go to Windows->Preferences... and choose Java->Installed JREs.

    To change just a single project's JRE you can go to Project->Properties and choose Java Build Path and choose the Libraries tab. Find the JRE System Library and click it, then choose Edit and choose the JRE (or JDK) that you want.

    If that doesn't work then when running the build file you can choose Run as->Ant Build... and click the JRE tab, choose separate JRE and specify the JRE you want there.

    0 讨论(0)
  • 2020-12-04 18:11

    If you are using Eclipse, try the following:

    • Right click on the ant build file, then choose "Properties".
    • Click on the "Run/Debug Settings", then click on the launch configuration file. You should be able to edit it then.
    • After you click "Edit", you should see a new window with a "Properties" tab which will show you a list of Ant build properties. There is a "java.home" property in the list. Make sure it refers to the correct path.
    0 讨论(0)
  • 2020-12-04 18:11

    Go to Environment variable and add

    JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_37
    

    till jdk path (exclude bin folder)
    now set JAVA_HOME into path as PATH=%JAVA_HOME%\bin;
    This will set java path to all the applications which are using java.

    For ANT use,

    ANT_HOME=C:\Program Files (x86)\apache-ant-1.8.2\bin;
    

    and include ANT_HOME into PATH, so path will look like PATH=%JAVA_HOME%\bin;%ANT_HOME%;

    0 讨论(0)
  • 2020-12-04 18:13

    In addition to verifying that the executables are in your path, you should also make sure that Ant can find tools.jar in your JDK. The easiest way to fix this is to add the tools.jar to the Ant classpath:

    0 讨论(0)
  • 2020-12-04 18:13

    Set environment variables

    This is the part that I always forget. Because you’re installing Ant by hand, you also need to deal with setting environment variables by hand.

    For Windows XP: To set environment variables on Windows XP, right click on My Computer and select Properties. Then go to the Advanced tab and click the Environment Variables button at the bottom.

    For Windows 7: To set environment variables on Windows 7, right click on Computer and select Properties. Click on Advanced System Settings and click the Environment Variables button at the bottom.

    The dialog for both Windows XP and Windows 7 is the same. Make sure you’re only working on system variables and not user variables.

    The only environment variable that you absolutely need is JAVA_HOME, which tells Ant the location of your JRE. If you’ve installed the JDK, this is likely c:\Program Files\Java\jdk1.x.x\jre on Windows XP and c:\Program Files(x86)\Java\jdk1.x.x\jre on Windows 7. You’ll note that both have spaces in their paths, which causes a problem. You need to use the mangled name[3] instead of the complete name. So for Windows XP, use C:\Progra~1\Java\jdk1.x.x\jre and for Windows 7, use C:\Progra~2\Java\jdk1.6.0_26\jre if it’s installed in the Program Files(x86) folder (otherwise use the same as Windows XP).

    That alone is enough to get Ant to work, but for convenience, it’s a good idea to add the Ant binary path to the PATH variable. This variable is a semicolon-delimited list of directories to search for executables. To be able to run ant in any directory, Windows needs to know both the location for the ant binary and for the java binary. You’ll need to add both of these to the end of the PATH variable. For Windows XP, you’ll likely add something like this:

    ;c:\java\ant\bin;C:\Progra~1\Java\jdk1.x.x\jre\bin
    

    For Windows 7, it will look something like this:

    ;c:\java\ant\bin;C:\Progra~2\Java\jdk1.x.x\jre\bin
    

    Done

    Once you’ve done that and applied the changes, you’ll need to open a new command prompt to see if the variables are set properly. You should be able to simply run ant and see something like this:

    Buildfile: build.xml does not exist!
    Build failed
    
    0 讨论(0)
  • 2020-12-04 18:20

    Under Windows you need to follow:

    Start -> Control Panel -> System -> Advanced -> Environment Variables.

    ... and you need to set JAVA_HOME (which is distinct from the PATH variable you mention) to reference the JDK home directory, not the bin sub-directory; e.g. "C:\program files\java\jdk".

    0 讨论(0)
提交回复
热议问题