在 Android SDK 中设置 JAVA_HOME

2022-01-08 00:00:00 windows sdk android java

我与 JAVA_HOME 配置有一些冲突当我使用以下代码时 -

I have some conflicts with the JAVA_HOME configuration When I using the following code -

System.out.println(System.getenv("JAVA_HOME"));

我得到 - C:jdk1.6.0_23 这是正确的地方.但是,当我在 Android build.xml 上运行 Ant 命令时,我收到以下错误消息 -

I get - C:jdk1.6.0_23 which is the correct place. But, When I run Ant command on an Android build.xml, I got the following error message -

C:android-sdk-windows oolsantmain_rules.xml:361:找不到javac编译器;com.sun.tools.javac.Main 不上类路径.也许 JAVA_HOME 没有指向JDK.目前已设置到C:jdk1.6.0_23jre"

C:android-sdk-windows oolsantmain_rules.xml:361: 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. It is currently set to "C:jdk1.6.0_23jre"

如何解决?

谢谢,

艾尔

推荐答案

要将 Windows 下的 JAVA_HOME 环境变量永久设置为您提到的 JDK 目录,请执行以下操作:

To permanently set your JAVA_HOME Environment Variable under Windows to the JDK directory you've mentioned do the following:

  1. 单击开始,右键单击计算机并选择属性(您可以同时按住 windows 键并按下暂停/中断键).
  2. 点击左侧的高级系统设置.
  3. 点击底部的环境变量按钮.
  4. 单击系统变量"窗口下方的新建..."按钮.
  5. 输入以下内容:

  1. Click Start, right click on Computer and select properties (you can also hold down the windows key and press the pause/break key).
  2. Click on Advanced system settings on the left.
  3. Click the Environment Variables button on the bottom.
  4. Click the New... button below the System variables window.
  5. Enter the following:

    Variable name: JAVA_HOME
    Variable value: C:jdk1.6.0_23 

  • 点击Ok、Ok、Ok,关闭你在步骤1中打开的系统控制面板
  • 关闭并重新打开命令提示符.
  • 如果您使用的是 Eclipse,请跳过上述步骤并执行以下操作:

    If you are using Eclipse then skip the steps above and do the following:

    1. 单击窗口"菜单并选择首选项".
    2. 展开左侧的Ant入口,点击Runtime
    3. 单击右侧 Classpath 选项卡中的 Global Entries.
    4. 点击添加外部 JAR...
    5. 导航到 C:jdk1.6.0_23lib 并选择 tools.jar 然后点击打开.
    6. 点击确定关闭首选项窗口.

    但是,在您的情况下,您最好的选择可能是简单地将 C:jdk1.6.0_23in 附加到您的 PATH 环境变量中,使用我上面的第一组说明作为粗略指导.

    In your situation however your best bet would probably be to simply append C:jdk1.6.0_23in to your PATH env var using my first set of instructions above as a rough guideline.

    相关文章