如何在Ubuntu上通过终端使Sublime Text 3编译和运行Java。

huangapple go评论89阅读模式
英文:

How to make Sublime Text 3 compile and run java through terminal on Ubuntu

问题

我正在尝试创建一个Sublime Text 3构建系统,通过Ubuntu终端而不是Sublime窗口底部的内置窗口(我在红圈中标出了),来编译和运行我的Java代码。

当前我正在使用的构建系统是这样的:

{
   "shell_cmd": "javac \"$file\" && java \"$file_base_name\"",
   "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
   "selector": "source.java"
}

它可以工作,但不会像我想要的那样在终端中打开。在我的Windows机器上,我使用以下配置:

{
"cmd": ["javac", "$file_name","&&","start","cmd","/k","java", "$file_base_name"],
"path":"C:\\Program Files\\Java\\jdk-11.0.3\\bin",
"shell": true
}

这确实在cmd中运行,但显然是在Windows上而不是Linux。

这个问题与以下问题非常相似:
https://stackoverflow.com/questions/28416885/how-to-set-up-sublime-text-3-to-run-and-compile-java-on-linux,这就是我得到当前构建系统的地方,只是他们希望它在Sublime中运行而不是终端。

英文:

I am trying to create a Sublime Text 3 build system to compile and run my java code through the terminal on Ubuntu, not the built in window in the bottom of the Sublime window which i circled in red. 如何在Ubuntu上通过终端使Sublime Text 3编译和运行Java。
The current build system I'm using is this:

{
   "shell_cmd": "javac \"$file\" && java \"$file_base_name\"",
   "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
   "selector": "source.java",
}

Which works, just it doesn't open it in the terminal like i want it to. On my windows machine I use this:

{
"cmd": ["javac", "$file_name","&&","start","cmd","/k","java", "$file_base_name"],
"path":"C:\\Program Files\\Java\\jdk-11.0.3\\bin",
"shell": true
}

Which does run it in cmd, just obviously on windows not linux

This question is very similar to the following:
https://stackoverflow.com/questions/28416885/how-to-set-up-sublime-text-3-to-run-and-compile-java-on-linux which is where i got the current build system, just they wanted it to run in sublime not terminal

答案1

得分: 1

这是我在Ubuntu中使用Sublime的代码,它将弹出Gnome终端,然后在那里执行代码。

{
  "cmd": ["javac", "$file"],
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
  "working_dir": "${file_path}",
  "selector": "source.java",
  "variants": [
    {
      "name": "Run",
      "shell": true,
      "cmd": ["gnome-terminal -e 'bash -c \"java ${file_base_name};tput dim;tput setaf 6; echo; echo -------------------------------------------------------------------------------- ;tput sgr0;tput setaf 6;echo;echo  Done Shivam   now Press ENTER to continue; read line;exit; exec bash;\"'"]
    }
  ]
}
英文:

Here is my code for sublime in ubuntu which will popup gnome-terminal and then will execute the code there.

{
  "cmd": ["javac", "$file"],
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
  "working_dir": "${file_path}",
  "selector": "source.java",
  "variants":
  [
      {
          "name": "Run",
          "shell": true,
          "cmd": ["gnome-terminal -e 'bash -c \"java ${file_base_name};tput dim;tput setaf 6; echo; echo -------------------------------------------------------------------------------- ;tput sgr0;tput setaf 6;echo;echo  Done Shivam   now Press ENTER to continue; read line;exit; exec bash;\"'"]
      }
  ]    
}

huangapple
  • 本文由 发表于 2020年7月30日 16:15:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63168950.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定