.scala 파일 맨 앞줄에 shebang을 넣어준다.


  1 #!/usr/bin/env scala

  2

  3 println("hello")


파일 속성을 변경해준다.


$ chmod a+x test.scala


이제 바로 실행이 된다.


$ ./test.scala

hello



$ sbt 'inspect sbtVersion'

[info] Set current project to gilbird (in build file:/C:/cygwin64/home/gilbird/)

[info] Setting: java.lang.String = 0.13.9

[info] Description:

[info]  Provides the version of sbt.  This setting should be not be modified.

[info] Provided by:

[info]  */*:sbtVersion

[info] Defined at:

[info]  (sbt.Defaults) Defaults.scala:135

[info] Delegates:

[info]  *:sbtVersion

[info]  {.}/*:sbtVersion

[info]  */*:sbtVersion

[info] Related:

[info]  */*:sbtVersion




$ sbt sbt-version

[info] Set current project to root--sbt (in build file:/C:/cygwin64/home/gilbird/.sbt/)

[info] 0.13.9

sdk manager를 이용하여 scala를 간단하게 설치해보자.


먼저 sdkman을 설치한다.


$ curl -s get.sdkman.io | bash


그 다음 새창을 열거나 다음 커맨드로 sdkman을 실행가능하도록 한다.

$ source "$HOME/.sdkman/bin/sdkman-init.sh"
다음 커맨드로 scala를 설치하면 작업 완료이다.

[~]# sdk install scala

==== BROADCAST =================================================================

* 08/02/16: Gradle 2.11 released on SDKMAN! #gradle

* 06/02/16: Vertx 3.2.1 released on SDKMAN! #vertx

* 04/02/16: Kotlin 1.0.0-rc-1036 released on SDKMAN! #kotlin

================================================================================


Downloading: scala 2.11.7


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0

100 27.1M  100 27.1M    0     0   360k      0  0:01:17  0:01:17 --:--:--  344k


Installing: scala 2.11.7

Done installing!


Do you want scala 2.11.7 to be set as default? (Y/n):  y


Setting scala 2.11.7 as default.

[~]# which scala

/Users/gilbird/.sdkman/candidates/scala/current/bin/scala





sbteclipse를 설치하면 sbt eclipse 커맨드로 eclipse 프로젝트를 생성할 수 있다.


먼저 sbteclipse 플러그인 사용을 위한 설정을 한다.

프로젝트 디렉토리에서 project 디렉토리와 plugins.sbt 파일을 생성한다.


mkdir project

vi project/plugins.sbt


다음 내용추가 


addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")


프로젝트 디렉토리에서 다음 커맨드 실행


# sbt eclipse

[info] Loading global plugins from /Users/gilbird/.sbt/0.13/plugins

[info] Updating {file:/Users/gilbird/.sbt/0.13/plugins/}global-plugins...

[info] Resolving org.fusesource.jansi#jansi;1.4 ...

[info] downloading https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.10/sbt_0.13/4.0.0/jars/sbteclipse-plugin.jar ...

[info] [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-plugin;4.0.0!sbteclipse-plugin.jar (6861ms)

[info] downloading https://jcenter.bintray.com/org/scalaz/scalaz-core_2.10/7.1.0/scalaz-core_2.10-7.1.0.jar ...

[info] [SUCCESSFUL ] org.scalaz#scalaz-core_2.10;7.1.0!scalaz-core_2.10.jar(bundle) (9362ms)

[info] downloading https://jcenter.bintray.com/org/scalaz/scalaz-effect_2.10/7.1.0/scalaz-effect_2.10-7.1.0.jar ...

[info] [SUCCESSFUL ] org.scalaz#scalaz-effect_2.10;7.1.0!scalaz-effect_2.10.jar(bundle) (1953ms)

[info] Done updating.

[info] Set current project to ScalaTest (in build file:/Users/gilbird/Work/scala/ScalaTest/)

[info] About to create Eclipse project files for your project(s).

[info] Updating {file:/Users/gilbird/Work/scala/ScalaTest/}scalatest...

[info] Resolving org.fusesource.jansi#jansi;1.4 ...

[info] downloading https://jcenter.bintray.com/org/scala-lang/scala-library/2.10.1/scala-library-2.10.1.jar ...

[info] [SUCCESSFUL ] org.scala-lang#scala-library;2.10.1!scala-library.jar (6513ms)

[info] downloading https://jcenter.bintray.com/org/scala-lang/scala-compiler/2.10.1/scala-compiler-2.10.1.jar ...

[info] [SUCCESSFUL ] org.scala-lang#scala-compiler;2.10.1!scala-compiler.jar (10524ms)

[info] downloading https://jcenter.bintray.com/org/scala-lang/scala-reflect/2.10.1/scala-reflect-2.10.1.jar ...

[info] [SUCCESSFUL ] org.scala-lang#scala-reflect;2.10.1!scala-reflect.jar (3837ms)

[info] downloading https://jcenter.bintray.com/org/scala-lang/jline/2.10.1/jline-2.10.1.jar ...

[info] [SUCCESSFUL ] org.scala-lang#jline;2.10.1!jline.jar (2989ms)

[info] Done updating.

[info] Successfully created Eclipse project files for project(s):

[info] ScalaTest


ls를 해보면 .project파일이 생성되어 있다.


# ls

total 24

0 ./          8 .classpath  0 .settings/  0 lib/        0 src/

0 ../         8 .project    8 build.sbt   0 project/    0 target/


그 다음은 기존의 이클립트 프로젝트 import를 하면된다.



다음 주소에서 스크립트를 sbtmkdirs.sh 스크립트를 다운로드 받는다.

https://gist.github.com/alvinj/3194379


프로젝트를 만들고자 하는 디렉토리에서 스크립트를 실행하고 

몇가지 물음에 답하면 하위에 해당 프로젝트가 만들어진다.


# sbtmkdirs.sh

This script creates an SBT project directory beneath the current directory.


Directory/Project Name (MyFirstProject): ScalaTest

Create .gitignore File? (Y/n): n

Create README.md File? (Y/n): n


-----------------------------------------------

Directory/Project Name: ScalaTest

Create .gitignore File?: n

Create README.md File?: n

-----------------------------------------------

Create Project? (Y/n): y


Project created. See the following URL for build.sbt examples:

http://alvinalexander.com/scala/sbt-syntax-examples

[~/work/scala]#


스크립트 실행 후 다음 디렉토리 및 파일이 생성된 것을 확인할 수 있다.


# ls ScalaTest/

total 8

0 ./         0 ../        8 build.sbt  0 lib/       0 project/   0 src/       0 target/

+ Recent posts