Sublime Forum

3126 how can i run .java file? not able to do it, help!

#1

Hello

the thing is that i haven’t been able to run .java

i created the properly .sublime-build i think and it doesn’t work for me

This is the command i used for .sublime-build
/// BEGIN CODE
{
“cmd”: “javac $file_name && java $file_base_name”,
“file_regex”: “^(…?):([0-9]):?([0-9]*)”,
“path”: “C:\Program Files\Java\jdk1.8.0_121\bin\”,
“selector”: “source.java”,
“shell”: true
}
/// END OF CODE

When i try to run it, a little message appears saying: “Building”, at 3 seconds this message dissapear
and the run windows Remains blank

HELP ME PLEASE!!, Ii don’t know what i do to fix it.
Note: I have Windows 10 Home, SDK 1…8.0 121 and Sublime Text 3 Build 3126
Note 2: Sorry for my english, my native language is Spanish…

0 Likes

Java sublime repl is very slow
#2

try replacing that with

"shell_cmd": "javac $file_name && java $file_base_name",

(there’s also this popular package)

1 Like

#3

That build system works for me, but you can obviously not execute it inside a build file.

PS "cmd" and "shell": true is the outdated version of "shell_cmd".

1 Like

#4

Thanks for try to help me, i already know what was it, my build command were always good, the problem was that i didn’t know ST3 doesn’t recognize ‘Scanner’ inputs, now i have other problem and its the next:

Is there a way that ST3 is able to read inputs?

i hope you undertood my message and new question :slightly_smiling:

0 Likes

#5

ST3 itself does not accept input in the build system, but you can run it in a terminal to accept inputs. My java build system:

{
    "shell_cmd": "javac $file_name && java $file_base_name",
    "selector": "source.java",
    "variants": [
        {
            "name":  "Terminal",
            "windows": {
                "shell_cmd": "start /i javac $file && java ${file/.java//g} && pause"
            }
        }
    ]
}

If you have inputs just press ctrl+shift+b and select Terminal. This is not perfect, but does work.

2 Likes

I get no output w/ ST3 but it's vice versa in NetBeans
#6

Thanks, i saw a video on youtube with the same purpose, the code is a command different than yours
and worked perfect for me.

is this:

/// BEGIN CODE
{
“cmd”: [“runJava.bat”, “$file”],
“file_regex”: “^(…?):([0-9]):?([0-9]*)”,
“selector”: “source.java”
}
/// END OF CODE

and second command saved as .bat and lodged inside jdk bin folder,
this is:

/// BEGIN CODE
@ECHO OFF
cd %~dp1
ECHO Compiling %~nx1…
IF EXIST %~n1.class (
DEL %~n1.class
)
javac -Xlint:unchecked %~nx1
IF EXIST %~n1.class (
ECHO Running %~n1…
start cmd /k java -ea %~n1
)
/// END OF CODE

i tried your command and didn’t work for me:

it said me this:

///
[Finished in 2.7s with exit code 1]
[shell_cmd: start /i javac C:\Users\andre\Desktop\U\PROGRAMACIÓN\TOTEACHER\Taller8_Punto12.java && java C:\Users\andre\Desktop\U\PROGRAMACIÓN\TOTEACHER\Taller8_Punto12 && pause]
[dir: C:\Users\andre\Desktop\U\PROGRAMACIÓN\TOTEACHER]
[path: C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\TXE Components\TCS;C:\Program Files\Intel\TXE Components\TCS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\TXE Components\DAL;C:\Program Files (x86)\Intel\TXE Components\DAL;C:\Program Files\Intel\TXE Components\IPT;C:\Program Files (x86)\Intel\TXE Components\IPT;C:\Program Files (x86)\Skype\Phone;C:\Program Files\Java\jdk1.8.0_121\bin;C:\Program Files\Java\jdk1.8.0_121\bin]
///

0 Likes

#7

Then, is there not a way to be able to run directly inside the ST3? :confused:
it makes me very upset that ST3 doesn’t have this function, is very rare for me and
it’s a very negative point for ST3

I hope the developers read this message…

0 Likes