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:
我有一个Windows 7系统,我安装了最新的Java编译器。我还有最新的Cygwin。我想使用Cygwin shell中的Java编译器。我对Cygwin中的PATH变量进行了如下编辑:
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二进制文件,但是当我尝试编译我的*时。java文件给我:
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.
我在设置路径变量时做错了吗?我还需要做点什么吗?我是Java新手,对cygwin不是很熟悉。
4 个解决方案
#1
60
as you write the it with double-quotes, you don't need to escape spaces with \
当您使用双引号编写it时,您不需要使用\来转义空格
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/
#2
5
Java binaries may be under "Program Files" or "Program Files (x86)": those white spaces will likely affect the behaviour.
Java二进制文件可以在“程序文件”或“程序文件(x86)”下:这些空格可能会影响行为。
In order to set up env variables correctly, I suggest gathering some info before starting:
为了正确设置env变量,我建议在开始之前收集一些信息:
- Open DOS shell (type cmd into 'RUN' box) go to C:\
- 打开DOS shell(在“运行”框中输入cmd)到C:\
- type "dir /x" and take note of DOS names (with ~) for "Program Files *" folders
- 键入“dir /x”并注意“程序文件*”文件夹的DOS名称(with ~)
Cygwin configuration:
Cygwin配置:
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)
go under C:\cygwin\home\,然后打开.bash_profile并添加以下两行(为了匹配您实际的JDK路径,可以方便地定制)
export JAVA_HOME="/cygdrive/c/PROGRA~1/Java/jdk1.8.0_65"
export PATH="$JAVA_HOME/bin:$PATH"
Now from Cygwin launch
现在从Cygwin发射
javac -version
javac - version
to check if the configuration is successful.
检查配置是否成功。
#3
2
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!
如果你仍然发现默认错误的Java版本(1.7)被用来代替Java主目录,那么所有你需要做的只是改变你的PATH变量的顺序设置JAVA_HOME \ bin之前你的Windows目录在你的路径变量,保存并重启cygwin。测试一下,确保一切正常。它不应该产生任何负面影响,因为您希望您自己的Java版本覆盖Windows附带的默认值。好运!
#4
2
To bring more prominence to the useful comment by @johanvdw:
为了突出@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.
如果您想确保您的javac文件路径总是知道cygwin何时开始,您可以编辑.bash_profile文件。在本例中,您将在文件中的某处添加export PATH=$PATH:“/cygdrive/C/程序文件/Java/jdk1.6.0_23/bin/”。
When Cygwin starts, it'll search directories in PATH and this one for executable files to run.
当Cygwin启动时,它将在路径中搜索目录,而在这个目录中搜索要运行的可执行文件。
#1
60
as you write the it with double-quotes, you don't need to escape spaces with \
当您使用双引号编写it时,您不需要使用\来转义空格
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/
#2
5
Java binaries may be under "Program Files" or "Program Files (x86)": those white spaces will likely affect the behaviour.
Java二进制文件可以在“程序文件”或“程序文件(x86)”下:这些空格可能会影响行为。
In order to set up env variables correctly, I suggest gathering some info before starting:
为了正确设置env变量,我建议在开始之前收集一些信息:
- Open DOS shell (type cmd into 'RUN' box) go to C:\
- 打开DOS shell(在“运行”框中输入cmd)到C:\
- type "dir /x" and take note of DOS names (with ~) for "Program Files *" folders
- 键入“dir /x”并注意“程序文件*”文件夹的DOS名称(with ~)
Cygwin configuration:
Cygwin配置:
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)
go under C:\cygwin\home\,然后打开.bash_profile并添加以下两行(为了匹配您实际的JDK路径,可以方便地定制)
export JAVA_HOME="/cygdrive/c/PROGRA~1/Java/jdk1.8.0_65"
export PATH="$JAVA_HOME/bin:$PATH"
Now from Cygwin launch
现在从Cygwin发射
javac -version
javac - version
to check if the configuration is successful.
检查配置是否成功。
#3
2
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!
如果你仍然发现默认错误的Java版本(1.7)被用来代替Java主目录,那么所有你需要做的只是改变你的PATH变量的顺序设置JAVA_HOME \ bin之前你的Windows目录在你的路径变量,保存并重启cygwin。测试一下,确保一切正常。它不应该产生任何负面影响,因为您希望您自己的Java版本覆盖Windows附带的默认值。好运!
#4
2
To bring more prominence to the useful comment by @johanvdw:
为了突出@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.
如果您想确保您的javac文件路径总是知道cygwin何时开始,您可以编辑.bash_profile文件。在本例中,您将在文件中的某处添加export PATH=$PATH:“/cygdrive/C/程序文件/Java/jdk1.6.0_23/bin/”。
When Cygwin starts, it'll search directories in PATH and this one for executable files to run.
当Cygwin启动时,它将在路径中搜索目录,而在这个目录中搜索要运行的可执行文件。