2

I am using MobaXterm, a friendly Unix terminal that runs on Windows. I want to compile a simple Java program using the javac command. After looking at plenty of other forums, I know I need to use the path where Java is installed, but no matter what I try, I keep getting the error

javac command not found

on the terminal. Can someone please help me out with compiling basic Java programs from within their directory on a Unix terminal on Windows?

And yes, I have JDK for Windows installed on my computer, I just don't know how to use it when compiling through the terminal.

7
  • What are the things you have tried? Perhaps we can point you where you're going wrong. Does your PATH include where javac is? Commented Jan 31, 2014 at 3:46
  • Have you already tried including <java_install_dir>/bin in your PATH env variable? Are you quite sure you installed the JDK and not the JRE? Commented Jan 31, 2014 at 3:46
  • 1
    are you having a session with a remote Unix machine. make sure you install java on that remote Unix machine and set the path correctly. Install java on Local machine can't help. try echo $PATH Commented Jan 31, 2014 at 3:47
  • 1
    This worked for me: export PATH=$PATH:/drives/c/Applications/Java/jdk1.7.0_45/bin and then javac (Note that a path on the C: drive must start with /drives/c like I have it above and that it must have forward slashes - of course the actual directories will differ) Commented Jan 31, 2014 at 3:54
  • The tools is probably based on cygwin. The path may be cygwin style. (See Jerry Jeremiah 's comment) See docs : mobaxterm.mobatek.net/support/documentation.html#2_1 Commented Jan 31, 2014 at 4:22

2 Answers 2

6

By default, MobaXterm does not preserve Windows PATH environment variable: this is why you obtain

command not found

when running javac. In order to tell MobaXterm to preserve Windows PATH, you just have to go to Settings --> Configuration --> Terminal tab and check Append Windows PATH environment variable option.

Sign up to request clarification or add additional context in comments.

2 Comments

This works to an extent. I can add the path to my javac in jdk to my existing path in MobaXterm. However, this does not save everytime I close and reopen MobaXterm. How do I save that path change?
You may add the following command to your "/home/mobaxterm/.profile" script: export PATH="$PATH:/drives/c/your/path/to/java" If the ".profile" file does not exist, you should create it first.
0

You can try cygwin first of all. Is another terminal that runs on windows. With this command 'sudo apt-get install openjdk-7-jdk' at linux installs the jdk And after this you can compile your program. sudo is for administration privilages.

1 Comment

Cygwin isn't Linux. Apt-cyg is the equivalent, or the normal setup program- that said, you could still use the existing jdk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.