hey guys i just started using sublime text 3 for java and i am really liking it there is one issue that i am getting is i am using a custom build for java
{
“cmd”: [“javac”, “$file_name”,"&&",“start”,“cmd”,"/k",“java”, “$file_base_name”],
“path”:“C:\Program Files\Java\jdk-14.0.2\bin”,
“shell”: true
}
this is the build system that i use it runs java and opens a terminal ever time i run java is there a way to run this on a existing terminal or closing the last terminal when opening a new one
i also saw something called terminus but i dont know how to build inside the terminus (i dont wanna type the “javac & java” command in terminus everytime i need to run the java file )and not in the cmd plz can someone help me
thanks in advance
How to run build system on existing terminal
If your java application doesn’t require interactive command line, you could propably try to just
{
"cmd": ["javac", "$file_name", "&&", "start", "java", "$file_base_name"],
"path":"C:\Program Files\Java\jdk-14.0.2\bin",
"shell": true
}
You might even want to try to drop "start"
to keep your java app print outputs to ST’s build panel.
{
"cmd": ["javac", "$file_name", "&&", "java", "$file_base_name"],
"path":"C:\Program Files\Java\jdk-14.0.2\bin",
"shell": true
}
Terminus can be defined as build system target, which may be the better choice if your application requires interactive command line input.
The following should do the job then.
{
"target": "terminus_open",
"selector": "source.java",
"cmd": ["javac", "$file_name", "&&", "java", "$file_base_name"],
"env": {
},
"cwd": "C:\\Program Files\\Java\\jdk-14.0.2\\bin",
"auto_close": false,
"panel_name": "java_run",
}
this is the error
error: invalid flag:
Usage: javac
use --help for a list of possible options
process is terminated with return code 2.
while using terminus code
Don’t have a java jdk installed to try things out, but the error may be caused by terminus executing the “cmd” directly, which causes javac to think the &&
to be part of its arguments.
Hence replacing “cmd” line by "shell_cmd": "javac \"$file_name\" && java \"$file_base_name\"",
may help to run it via shell and have the script interpreted correctly.
You might want to study the readme on https://github.com/randy3k/Terminus for information how to configure Terminus.
EDIT: You may also try $file
instead of $file_name
in case you need the absolute path to be passed to the compiler.