@ECHO OFF
cd %~dp1
ECHO Compiling %~nx1.......
IF EXIST %~n1.class (
DEL %~n1.class
)
javac %~nx1
IF EXIST %~n1.class (
ECHO -----------OUTPUT-----------
java %~n1
)
{
"shell_cmd": "runJava.bat \"$file\"",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"encoding": "cp936"
}
编码cp936是为了解决程序中有中文而导致的各种问题
{
"cmd": ["javac","-encoding","gbk","-d",".","$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"encoding":"gbk",
"variants":
[
{
"name": "Run",
"shell": true,
"cmd" : ["start","cmd","/c", "java ${file_base_name}&pause"],
"working_dir": "${file_path}",
"encoding":"gbk"
}
]
}
另存为Java.sublime-build,注意图中的红色标记的地方,可以写成gbk或者cp936都是可以的,这三个地方要统一,不然又会出现莫名其妙的中文编码错误问题,保存后再按CTRL+B就是执行javac命令,按CTRL+SHIFT+B就会执行java命令,弹出熟悉的CMD窗口,然后就可以很顺手的输入数据等等了,保存以后这个文件默认是保存在C:\Users\Administrator\AppData\Roaming\Sublime Text 3\Packages\User这个目录下的,可是撸主有强迫症啊有木有,放在这里看着就是不爽不和谐啊,于是就把Java.sublime-build移动到了Packages文件夹下的Java.sublime-package这个文件里面,保存,然后就终于解决了心头这个疙瘩了,呵呵
希望能帮到需要的朋友,大家共同学习~~~
上面新建的那个Build文件还是对中文支持有问题,就是如果用ST新建java文件,运行有中文的程序的时候就会有问题,然后现在重新修改一下,可以用了,代码如下:
{
"cmd": ["javac", "${file}", "-encoding", "UTF-8"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"working_dir": "${file_path}",
"selector": "source.java",
"encoding": "cp936",
"shell": true,
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/c", "javac", "${file}", "-encoding", "UTF-8", "&&", "start", "cmd", "/c", "java ${file_base_name} & echo. & pause"]
},
]
}