Locked History Actions

Diff for "sbt/Getting-Started-Running"

Differences between revisions 1 and 2
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Running [[https://github.com/harrah/xsbt/wiki/Getting-Started-Running]]の翻訳(2011/10/26時点)
Line 5: Line 5:
    Page History ここでは、プロジェクトをセットアップした後のsbtの使い方をみていく。
sbtをインストールして、Hello, Worldか何かのプロジェクトを作成済であることが前提だ。
Line 7: Line 8:
Previous Getting Started Guide page 5 of 14. Next === 対話モード ===
Line 9: Line 10:
This page describes how to use sbt once you have set up your project. It assumes you've installed sbt and created a Hello, World or other project.
Interactive mode
プロジェクトディレクトリの中で引数無しでsbtを起動する
{{{
$ sbt
}}}
Line 12: Line 15:
Run sbt in your project directory with no arguments: コマンド引数なしで起動すると対話モードになる。
対話モードではコマンドプロンプトが使える(しかもタブ補完と履歴付き!)
Line 14: Line 18:
$ sbt 例えば、プリンプとでcompileとタイプする
Line 16: Line 20:
Running sbt with no command line arguments starts it in interactive mode. Interactive mode has a command prompt (with tab completion and history!). {{{
> compile
}}}
もう一度コンパイルしたいときは、上矢印を押してEnterを押せばいい。
Line 18: Line 25:
For example, you could type compile at the sbt prompt: 君のプログラムを起動したい場合はrunだ。
Line 20: Line 27:
> compile 対話モードを終了させたいときは、exitとタイプするか、あるいはCtrl+D(Unitの場合)あるいはCtrl+Z(Windowsの場合)。
Line 22: Line 29:
To compile again, press up arrow and then enter. === バッチモード ===
Line 24: Line 31:
To run your program, type run. sbtをバッチモードで起動することもできる。
これには、空白で区切られたsbtのアクションを引数として与えればいい。
Line 26: Line 34:
To leave interactive mode, type exit or use Ctrl+D (Unix) or Ctrl+Z (Windows).
Batch mode
引数をとるsbtコマンドに対しては、コマンドと引数をクォートで囲む。こんなふうに
{{{
$ sbt clean compile "test-only TestA TestB"
}}}
Line 29: Line 39:
You can also run sbt in batch mode, specifying a space-separated list of sbt actions as arguments. For sbt commands that take arguments, pass the command and arguments as one argument to sbt by enclosing them in quotes. For example, この例では、test-onlyにTestAとTestBという引数が与えられる。
そして、示された順(clean, compile, test-only)にアクションが実行される。
Line 31: Line 42:
$ sbt clean compile "test-only TestA TestB" == 継続的なビルドとテスト ==
Line 33: Line 44:
In this example, test-only has arguments, TestA and TestB. The actions will be run in sequence (clean, compile, then test-only).
Continuous build and test

To speed up your edit-compile-test cycle, you can ask sbt to automatically recompile or run tests whenever you save a source file.
edit-compile-testサイクルを素早くするには、君がソースファイルを保存した途端に自動的にコンパイルされるといいよね。
Line 40: Line 48:
{{{
Line 41: Line 50:
}}}
Line 47: Line 57:
Common actions
== 共通アクション ==
Line 51: Line 62:
    clean Deletes all generated files (in the target directory).
    compile Compiles the main sources (in src/main/scala and src/main/java directories).
    test Compiles and runs all tests.
    console Starts the Scala interpreter with a classpath including the compiled sources and all dependencies. To return to sbt, type :quit, Ctrl+D (Unix), or Ctrl+Z (Windows).
    run <argument>* Runs the main class for the project in the same virtual machine as sbt.
    package Creates a jar file containing the files in src/main/resources and the classes compiled from src/main/scala and src/main/java.
    help <command> Displays detailed help for the specified command. If no command is provided, displays brief descriptions of all commands.
    reload Reloads the build definition (build.sbt, project/*.scala, project/*.sbt files). Needed if you change the build definition.
 * clean Deletes all generated files (in the target directory).
 * compile Compiles the main sources (in src/main/scala and src/main/java directories).
 * test Compiles and runs all tests.
 * console Starts the Scala interpreter with a classpath including the compiled sources and all dependencies. To return to sbt, type :quit, Ctrl+D (Unix), or Ctrl+Z (Windows).
 * run <argument>* Runs the main class for the project in the same virtual machine as sbt.
 * package Creates a jar file containing the files in src/main/resources and the classes compiled from src/main/scala and src/main/java.
 * help <command> Displays detailed help for the specified command. If no command is provided, displays brief descriptions of all commands.
 * reload Reloads the build definition (build.sbt, project/*.scala, project/*.sbt files). Needed if you change the build definition.
Line 60: Line 71:
Tab completion == タブ補完 ==
Line 63: Line 74:
History Commands
== 履歴コマンド ==
Line 67: Line 79:
    ! Show history command help.
    !! Execute the previous command again.
    !: Show all previous commands.
    !:n Show the last n commands.
    !n Execute the command with index n, as shown by the !: command.
    !-n Execute the nth command before this one.
    !string Execute the most recent command starting with 'string'
    !?string Execute the most recent command containing 'string'
 * ! Show history command help.
 * !! Execute the previous command again.
 * !: Show all previous commands.
 * !:n Show the last n commands.
 * !n Execute the command with index n, as shown by the !: command.
 * !-n Execute the nth command before this one.
 * !string Execute the most recent command starting with 'string'
 * !?string Execute the most recent command containing 'string'

sbtの実行

https://github.com/harrah/xsbt/wiki/Getting-Started-Runningの翻訳(2011/10/26時点)

ここでは、プロジェクトをセットアップした後のsbtの使い方をみていく。 sbtをインストールして、Hello, Worldか何かのプロジェクトを作成済であることが前提だ。

対話モード

プロジェクトディレクトリの中で引数無しでsbtを起動する

$ sbt

コマンド引数なしで起動すると対話モードになる。 対話モードではコマンドプロンプトが使える(しかもタブ補完と履歴付き!)

例えば、プリンプとでcompileとタイプする

> compile

もう一度コンパイルしたいときは、上矢印を押してEnterを押せばいい。

君のプログラムを起動したい場合はrunだ。

対話モードを終了させたいときは、exitとタイプするか、あるいはCtrl+D(Unitの場合)あるいはCtrl+Z(Windowsの場合)。

バッチモード

sbtをバッチモードで起動することもできる。 これには、空白で区切られたsbtのアクションを引数として与えればいい。

引数をとるsbtコマンドに対しては、コマンドと引数をクォートで囲む。こんなふうに

$ sbt clean compile "test-only TestA TestB"

この例では、test-onlyにTestAとTestBという引数が与えられる。 そして、示された順(clean, compile, test-only)にアクションが実行される。

継続的なビルドとテスト

edit-compile-testサイクルを素早くするには、君がソースファイルを保存した途端に自動的にコンパイルされるといいよね。

Make an action run when one or more source files change by prefixing the action with ~. For example, in interactive mode try:

> ~ compile

Press enter to stop watching for changes.

You can use the ~ prefix with either interactive mode or batch mode.

See Triggered Execution for more details.

共通アクション

Here are some of the most common sbt commands. For a more complete list, see Command Line Reference.

  • clean Deletes all generated files (in the target directory).
  • compile Compiles the main sources (in src/main/scala and src/main/java directories).
  • test Compiles and runs all tests.
  • console Starts the Scala interpreter with a classpath including the compiled sources and all dependencies. To return to sbt, type :quit, Ctrl+D (Unix), or Ctrl+Z (Windows).
  • run <argument>* Runs the main class for the project in the same virtual machine as sbt.

  • package Creates a jar file containing the files in src/main/resources and the classes compiled from src/main/scala and src/main/java.
  • help <command> Displays detailed help for the specified command. If no command is provided, displays brief descriptions of all commands.

  • reload Reloads the build definition (build.sbt, project/*.scala, project/*.sbt files). Needed if you change the build definition.

タブ補完

Interactive mode has tab completion, including at an empty prompt. A special sbt convention is that pressing tab once may show only a subset of most likely completions, while pressing it more times shows more verbose choices.

履歴コマンド

Interactive mode remembers history, even if you exit sbt and restart it. The simplest way to access history is with the up arrow key. The following commands are also supported:

  • ! Show history command help.
  • !! Execute the previous command again.
  • !: Show all previous commands.
  • !:n Show the last n commands.
  • !n Execute the command with index n, as shown by the !: command.
  • !-n Execute the nth command before this one.
  • !string Execute the most recent command starting with 'string'
  • !?string Execute the most recent command containing 'string'