Sublime Text 2 构建系统编译&在新的终端/命令提示符窗口中运行 Java? [英] Sublime Text 2 build system to compile & run Java in a new Terminal/Command Prompt window?

查看:18
本文介绍了Sublime Text 2 构建系统编译&在新的终端/命令提示符窗口中运行 Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Sublime Text 2 中创建一个构建系统来编译 Java 文件,然后在终端(对于 OS X 或 Linux)或命令提示符(对于 Windows)中运行它) 窗口.

I would like to make a build system in Sublime Text 2 that will compile a Java file, and then run it in a new Terminal (for OS X or Linux) or Command Prompt (for Windows) window.

这是因为 Sublime Text 2 不允许用户输入任何东西,所以任何需要输入的程序在 Sublime Text 2 中运行时都会报错,如下所示:

The reason for this is because Sublime Text 2 doesn't allow users to input anything, so any programs requiring input will spit out an error when running inside Sublime Text 2, like this:

这是我目前拥有的(我也尝试过批处理文件),但它只是在 Sublime Text 2 中运行,而不是在新 shell 中运行:

This is what I currently have (I've also tried a batch file), but it simply runs inside Sublime Text 2, as opposed to in a new shell:

这可能吗?如果是这样,请逐步解释(我是 Sublime Text 2 的菜鸟),如何做;我已经尝试在 Sublime Text 2 论坛上发帖,但到目前为止没有运气!我会说不出的感激.感谢您的时间!

Is this possible? If so, please explain, step-by-step (I'm a noob at Sublime Text 2), how to do it; I've already tried posting on the Sublime Text 2 forums, and so far no luck! I'd be inexpressibly grateful. Thanks for your time!

推荐答案

这是我为完成这项工作所做的礼貌"(阅读:简短易读)版本.

Here's the "polite" (read: short and readable) version of what I did to make this work.

  • 这只是一个起点.Full impl 是一篇博文,而不是答案.
  • 假设:OS X、xterm、无包层次结构等
  • 包/项目内容相对直接,但 IMO 很尴尬.
  • 我没有一个完整的解决方案,可以跨操作系统或考虑奇怪的目录.
  • 我的真实版本做了一些假设,可能适用于世界其他地方,也可能不适用.
  • 我的真实版本使用 Ant 或 Maven,它解决了很多问题,但不是全部.
  • 其中一些可以包含在 sublime-build 文件中,但是…
  • …对我来说,这种方式更容易,因为这里没有显示其他内容.
  • This is a starting point only. Full impl is a blog post, not an answer.
  • Assumes: OS X, xterm, no package hierarchy, etc.
  • Package/project stuff is relatively straight-forward, but IMO awkward.
  • I don't have a complete solution that's cross-OS or that takes weird directories into account.
  • My real version makes some assumptions that may or may not work for the rest of the world.
  • My real version uses Ant or Maven, which solves many problems, but not all.
  • Some of this can be wrapped up in the sublime-build file, but…
  • …for me it's easier this way because of other stuff not shown here.

Nutshell(简化):编译并运行 shell 脚本以获得一个新窗口.

Nutshell (Simplification): compile and run through a shell script in order to get a new window.

脚本

cd $1
/usr/bin/javac $2
/usr/X11/bin/xterm -e "/bin/bash -c "/usr/bin/java $3; echo 'Press ENTER to quit...'; read line""

JavaC.sublime-build

{
  "cmd": ["~/bin/run-java.sh $file_path $file $file_base_name"],
  "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
  "path": "/usr/bin/java",
  "selector": "source.java",
  "shell": true
}

在现实生活中它有点复杂.

In real life it's a bit more complex.

说了这么多,我从来没有真正用 Java 中的控制台输入做任何事情;我通过 Groovy 或 JRuby REPL 来实现,或者允许存根输入/输出源/目标,或者…但不是在 Java 中,也不是来自 Sublime Text 2——我使用 IDE 进行 Java 开发.其他任何事情都是浪费我的时间,即使是简短的实验性内容.

All this said, I never really do anything with console input in Java proper; I do it via either a Groovy or JRuby REPL, or allow stubbing of input/output sources/destinations, or… but not in Java, and not from Sublime Text 2–I use an IDE for Java development. Anything else is a waste of my time, even for short, experimental stuff.

这篇关于Sublime Text 2 构建系统编译&在新的终端/命令提示符窗口中运行 Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆