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

问题描述

我想在Sublime Text 2中构建一个编译Java文件的构建系统,然后在 new 终端(用于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内部运行时吐出错误文字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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 00:09