Reputation: 483
My Java bin is added to the path, still it's not able to find the javac I think.
The thing works fine in eclipse IDE.
public class testing {
public static void main(String[] args) {
System.out.println("hi");
}
}
Below is the error from sublime text 2. Removed some intel path otherwise path was too long.
[Error 2] The system cannot find the file specified
[cmd: [u'javac', u'C:\\Users\.......\testing.Java']]
[dir: C:\Users.....
[path: C:\ProgramData\Oracle\Java\javapath;C:\Python27\;C:\Python27\Scripts;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Java\jre1.8.0_45\bin;]
[Finished]
If I run it in Sublime text 3 then the error is below.
'javac' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.0s with exit code 1]
I even tried the custom build but the error shown is same, below is the custom build.
MyJava.sublime-build
{
"cmd": ["javac", "$file_name", "&&", "java" ,"$file_base_name"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"path" : "C:\\Program Files\\Java\\jre1.8.0_45\\bin",
"selector": "source.java",
"shell":true
}
Please help due to this I haven't been using Sublime text and continuing with Eclipse but thought let me try again.
Below is my Java folder. As suggested I added jdk to the path.
But now error changes to below.
javac: invalid flag: C:\........GitHub\HackerRank\testing.Java
Usage: javac <options> <source files>
use -help for a list of possible options
[Finished in 0.3s with exit code 2]
Upvotes: 2
Views: 9091
Reputation: 483
First of all don't skip the details of how to build and run your program. In eclipse it happens by default that I wasn't even aware of path/javac/java etc.
Here are some great details on this What does "Could not find or load main class" mean?
j
not J
in file names. ( test.java)javac test.java
is used to compile the program which results in test.class
compiled program.java test
to run your program not java test.class
jdk
and not jre
ctrl+b
will only compile the program and not run it.Myjava.sublime-build
{
"cmd": ["javac", "$file_name", "&&", "java" ,"$file_base_name"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"path" : "C:\\Program Files\\Java\\jdk1.7.0_79\\bin",
"selector": "source.java",
"shell":true
}
This will both compile and run the program at same time.
Upvotes: 2
Reputation: 1346
Your path has the jre (Java Runtime Environment) bin directory, but no jdk (Java Development Kit), which is where javac is typically found. You'll need to find where your JDK lives and add that directory to your path as well.
Upvotes: 2