如何设置 Cygwin PATH 来查找 javac?

发布于 2024-10-16 07:37:29 字数 391 浏览 2 评论 0原文

我有一个 Windows 7 系统,上面安装了最新的 Java 编译器。我还有最新的 Cygwin。我想使用 Cygwin shell 中的 Java 编译器。我在 Cygwin 中编辑了 PATH 变量,如下所示:

export PATH=$PATH:"/cygdrive/C/Program\ Files/Java/jdk1.6.0_23/bin/"

我可以在上面的目录中看到 javac 二进制文件,但是当我尝试编译我的 *.java 文件时,我得到:

javac command not found

我在设置PATH 变量是这样的吗?我还需要做其他事情吗?我是Java新手,对cygwin不太熟悉。

I have a Windows 7 system on which I have installed the latest Java compiler. I also have the latest Cygwin. I want to use the Java compiler from Cygwin's shell. I edited the PATH variable in Cygwin as follows:

export PATH=$PATH:"/cygdrive/C/Program\ Files/Java/jdk1.6.0_23/bin/"

I can see the javac binary in the above directory, however when I try to compile my *.java file I get:

javac command not found

Am I doing something wrong in setting the PATH variable like this? Do I have to do something else? I am new to Java and not very familiar with cygwin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

囍孤女 2024-10-23 07:37:29

当你用双引号写它时,你不需要用 \ 转义空格,

export PATH=$PATH:"/cygdrive/C/Program Files/Java/jdk1.6.0_23/bin/"

当然这也有效:

export PATH=$PATH:/cygdrive/C/Program\ Files/Java/jdk1.6.0_23/bin/

as you write the it with double-quotes, you don't need to escape spaces with \

export PATH=$PATH:"/cygdrive/C/Program Files/Java/jdk1.6.0_23/bin/"

of course this also works:

export PATH=$PATH:/cygdrive/C/Program\ Files/Java/jdk1.6.0_23/bin/
江湖正好 2024-10-23 07:37:29

Java 二进制文件可能位于“Program Files”或“Program Files (x86)”下:这些空格可能会影响行为。

为了正确设置环境变量,我建议在开始之前收集一些信息:

  • 打开 DOS shell(在“RUN”框中键入 cmd)转到 C:\
  • 键入“dir /x”并记下“Program Files *”文件夹的 DOS 名称(带 ~)

Cygwin 配置:

转到 C:\cygwin\home\ 下,然后打开 .bash_profile 并添加以下两行(方便自定义,以便与您实际的 JDK 路径匹配)

export JAVA_HOME="/cygdrive/c/PROGRA~1/Java/jdk1.8.0_65"
export PATH="$JAVA_HOME/bin:$PATH"

现在从 Cygwin 启动

javac -version

来检查配置是否成功。

Java binaries may be under "Program Files" or "Program Files (x86)": those white spaces will likely affect the behaviour.

In order to set up env variables correctly, I suggest gathering some info before starting:

  • Open DOS shell (type cmd into 'RUN' box) go to C:\
  • type "dir /x" and take note of DOS names (with ~) for "Program Files *" folders

Cygwin configuration:

go under C:\cygwin\home\, then open .bash_profile and add the following two lines (conveniently customized in order to match you actual JDK path)

export JAVA_HOME="/cygdrive/c/PROGRA~1/Java/jdk1.8.0_65"
export PATH="$JAVA_HOME/bin:$PATH"

Now from Cygwin launch

javac -version

to check if the configuration is successful.

浅忆流年 2024-10-23 07:37:29

为了更加突出 @johanvdw 的有用评论:

如果您想确保 cygwin 启动时始终知道您的 javac 文件路径,您可以编辑 .bash_profile 文件。在此示例中,您将在文件中的某处添加 export PATH=$PATH:"/cygdrive/C/Program Files/Java/jdk1.6.0_23/bin/"

当 Cygwin 启动时,它将在 PATH 和此目录中搜索要运行的可执行文件。

To bring more prominence to the useful comment by @johanvdw:

If you want to ensure your your javac file path is always know when cygwin starts, you may edit your .bash_profile file. In this example you would add export PATH=$PATH:"/cygdrive/C/Program Files/Java/jdk1.6.0_23/bin/" somewhere in the file.

When Cygwin starts, it'll search directories in PATH and this one for executable files to run.

寻找一个思念的角度 2024-10-23 07:37:29

如果您仍然发现使用默认错误的 Java 版本 (1.7) 而不是 Java 主目录,那么您所需要做的就是更改 PATH 变量的顺序,将 JAVA_HOME\bin 设置在 Windows 目录之前。 PATH变量,保存并重新启动cygwin。进行测试以确保一切正常。它不应该产生任何不利影响,因为您希望自己的 Java 版本覆盖 Windows 附带的默认版本。祝你好运!

If you are still finding that the default wrong Java version (1.7) is being used instead of your Java home directory, then all you need to do is simply change the order of your PATH variable to set JAVA_HOME\bin before your Windows directory in your PATH variable, save it and restart cygwin. Test it out to make sure everything will work fine. It should not have any adverse effect because you want your own Java version to override the default which comes with Windows. Good luck!

匿名。 2024-10-23 07:37:29

尽管所有其他答案在技术上都是正确的,但我建议您将自定义路径添加到 PATH 的开头,而不是末尾。这样,它将是第一个要查找的位置,而不是最后一个:

添加到 ~/.bash_profile 的底部:

export PATH="/cygdrive/C/Program Files/Java/jdk1.6.0_23/bin/":$PATH

这样,如果您有多个 java 或 < code>javac 它将使用您首先提供的那个。

Although all other answers are technically correct, I would recommend you adding the custom path to the beginning of your PATH, not at the end. That way it would be the first place to look for instead of the last:

Add to bottom of ~/.bash_profile:

export PATH="/cygdrive/C/Program Files/Java/jdk1.6.0_23/bin/":$PATH

That way if you have more than one java or javac it will use the one you provided first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文