R.A.Kalniņš
R.A.Kalniņš

Reputation: 1

Java compile in Sublime Text 3

I'm trying to compile java in Sublime text 3. I have made PATH to Java bin and made a build file, but I get this on the first compile in Sublime terminal and nothing changes after subsequent compiles. I got C to compile but can't figure java.

str expected, not list
    [cmd: ['javac', 'hello.java', '&&', 'java', 'hello']]
    [dir: C:\code\java\second]
    [path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;"C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;";"C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\MinGW\bin;C:\MinGW\MSYS\1.0\bin";C:\Program Files\Java\jdk1.8.0_191\bin;C:\MinGW\bin;C:\cygwin64\bin;"C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\QuickTime\QTSystem;C:\cygwin64\bin";C:\Users\Rudolfs\AppData\Local\Microsoft\WindowsApps;C:\Users\Rudolfs\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Rudolfs\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\Java\jdk1.8.0_191\bin;]
    [Finished]

Upvotes: 0

Views: 195

Answers (3)

yakovbenalex
yakovbenalex

Reputation: 21

  1. Install Terminus by Package Control: Package Control: install > Terminus.
  2. Create new Build Systems Tools > Build Systems > New Build System
  3. Type in file next:
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"shell_cmd": "javac $file_name && java $file_base_name",
"working_dir": "$file_path"
}
  1. And save this file as RunJava.sublime-build for example.
  2. Select created Build System Tools > Build Systems > RunJava
  3. Then run your code by Tools > Build

P.S. If you have input, type it in console and press Enter. It works on Windows 11.

Upvotes: 0

Kaamil Mirza
Kaamil Mirza

Reputation: 1

  • Make sure you are building your system in java.

  • Make sure that you have saved you script file with .java extension

  • Make a new build and change the script in it to

    { "shell_cmd": "javac $file && java $file_base_name" }

Now go back to build and build it by using RunJava If you are still facing errors, it could be due to syntax errors so for that provide use with the whole code.

Upvotes: 0

rzwitserloot
rzwitserloot

Reputation: 102902

The && there is a bashism; you aren't running bash, you are running direct process access. It's as if you pass && directly to the javac process and javac has no idea what to do with it.

Check if sublime text has the ability to run 2 things in sequence (preferably not running the second thing if the first failed). If not, make a bash script and run that.

Upvotes: 1

Related Questions