简体   繁体   中英

Running Java on Sublime Text for Windows

I'm trying to compile and execute Java files on Sublime text. The JavaC build system does not work, which I'm assuming is normal because you're supposed to create a file with the build system code and save it in "Packages". I know this because I set it up for Python a while ago, and I've been using it normally.

I tried to do the same for Java, using the same build system code but changing the python parts to java. When using the build system I get an error saying that 'javac' is not recognized as an internal or external command,operable program or batch file.

For reference, here's what I have

{
  "cmd": ["javac", "$file", "&&", "java", "$file_base_name"],
  "shell": true,
  "path":"C:\\Program Files\\Java\\jdk-11.0.2\\bin\\java.exe",
  "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
  "selector": "source.java"
}

I'm trying to run a simple Hello World program. This is on Windows 10, and the file name is saved with the .sublime-build extension. What am I doing wrong?

The error message you're seeing indicates that when Sublime tells Windows to execute javac , Windows can't find it. The general reason for that is that the PATH environment variable doesn't contain the location where javac.exe is located.

In this case you've used the path key in the sublime-build file to explicitly set the path, but you're setting it to the name of the executable; path should contain the location where the executable can be found and not point to the executable itself.

You can fix this in one of two ways:

  1. Remove the path line and change the first item in cmd so it it includes the full path up to and including the javac.exe file; then Sublime will tell Windows to execute the file directly without having to look it up in the path.

  2. Modify the path line to remove the javac.exe part; then Sublime will tell windows to execute javac.exe and it will be able to find it in the directory indicated in the path.

More information on build systems (including problems similar to this one) can be found in the video Common Build Problems ( Disclaimer: I am the author of the video)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM