Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set my Cygwin PATH to find javac?

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.

like image 640
liv2hak Avatar asked Feb 07 '11 07:02

liv2hak


People also ask

How do I change the PATH in Cygwin?

Update the PATH environment variable: From the Start menu, select Parameters > Control Panel > System. Select the Advanced tab and click Environment variables. Edit the PATH environment variable to add the Cygwin installation directory, for example c:\cygwin\bin; and click OK.

How do I find the PATH in Cygwin?

I.e. DOS C: drive can be accessed in Cygwin by /cygdrive/c, D: as /cygdrive/d, etc. To display the contents of the current directory, you can use ls or dir commands. ls -la will provide more details, including file access permissions, size and modification date.


2 Answers

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/ 
like image 58
lweller Avatar answered Sep 22 '22 08:09

lweller


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.

like image 30
l__LG__l Avatar answered Sep 22 '22 08:09

l__LG__l