前回のjavaのクラスをscalaで継承では,ビルドツールを使わない説明でしたので,こちらはsafetype-activatorを利用するときの方法
typesafe-activatorの導入と簡単な使用例
環境
- OS : OS X El Capitan 10.11.5
- package manager : homebrew
- インストール方法 :
brew install typesafe-activator
typesafe-activator のコマンド
# 新規プロジェクト作成など色々 (Webインターフェイス)
activator ui
# テンプレート一覧
activator list-templates
# 新規プロジェクト作成 (コマンドライン)
activator new
# プロジェクトコンパイル
activator compile
# プロジェクト実行
activator run
# インタラクティブモード
activator shell
テストファイル
前回のjavaのクラスをscalaで継承 で使用した3つのファイルのパッケージを package com.example
, インポートを import com.example.<クラス名>
とした
プロジェクト生成
activator new
# Fetching the latest list of templates...
#
# Browse the list of templates: http://lightbend.com/activator/templates
# Choose from these featured templates or enter a template name:
# 1) minimal-akka-java-seed
# 2) minimal-akka-scala-seed
# 3) minimal-java
# 4) minimal-scala
# 5) play-java
# 6) play-scala
# (hit tab to see a list of all templates) ##<= テンプレート番号を入力 (今回は4)
# > 4
# Enter a name for your application (just press enter for 'minimal-scala') ##<= enter を入力
# >
# OK, application "minimal-scala" is being created using the "minimal-scala" template.
#
# 以下略
## 上記の3つのファイルをそれぞれ package を意識して, src ディレクトリ以下に適切に配置 ##
tree -L 1 && tree src
# .
# ├── LICENSE
# ├── bin
# ├── build.sbt
# ├── libexec
# ├── project
# ├── src
# └── target
#
# src
# ├── main
# │ ├── java
# │ │ └── com
# │ │ └── example
# │ │ └── Super.java
# │ └── scala
# │ └── com
# │ └── example
# │ ├── Main.scala
# │ └── Sub.scala
# └── test
# └── scala
# └── HelloSpec.scala
プロジェクト実行
activator run
# [info] Loading project definition from <path>/minimal-scala/project
# [info] Set current project to minimal-scala (in build file:/<path>/minimal-scala/)
#
# 途中略
#
# background log: info: Running com.example.Main
# background log: info: Hello from A in Super
# background log: info: Hello form B in Sub
# [success] Total time: 1 s, completed Jul 4, 2016 6:17:54 AM