初心者Scala in f@n 第五回 sbt+giter8
Upcoming SlideShare
Loading in...5
×
 

初心者Scala in f@n 第五回 sbt+giter8

on

  • 1,088 views

 

Statistics

Views

Total Views
1,088
Views on SlideShare
1,083
Embed Views
5

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 5

https://twitter.com 5

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

初心者Scala in f@n 第五回 sbt+giter8 初心者Scala in f@n 第五回 sbt+giter8 Presentation Transcript

  • Sbt + giter8 2012-12-04
  • まず何より先に… 1. sbt インストール 2. sbt 起動 3. giter8 インストール 4. giter8 起動できてます?結構時間がかかるのでまだの方はお早めに
  • ・ 伊藤 学 技術開発部開発課 scala をお仕事で使い始めて 1 ヶ月未満・ カメラ 水槽の魚写すカメラほしくてそろそろ買う 詳しい人に相談したらさっぱり分からん   買っても使いこなせるのか・・?
  • 使ってみる前に まだ実用化していないけど業務で調査実験したの を ご紹介
  • そのときは sbt なんてしらなかった 名前だけは知ってました Oracle から読み込んでメールを送信するバッチの Replace ・ scala でバッチ作ろう ・ play! で管理画面作ろう
  • そのバッチのほうの調査 DB へのアクセス できるかどうか 書いてみた
  • そのバッチを動かすために・ squeryl つかうので squeryl_2.9.0-0.9.4.jar をダウンロード・ cglib も必要みたいなので cglib-nodep-2.2.3.jar をダウンロードそしたらコマンド叩くscala -classpath ./jars/squeryl_2.9.0-0.9.4.jar:./jars/ojdbc14.jar:./jars/cglib-nodep-2.2.3.jarOracleTest3.scala
  • 動かせた!と経験者に報告・「 sbt つかってないからデプロイ大変そうですね」・!?・ sbt?
  • ・ sbt/htmlmailsender-project/project/HtmlmailsenderProjectBuild.scala を修正
  • ・ sbt だとこれで OK$ ~/sbt/htmlmailsender-project/$ sbt run ご紹介終わり
  • Sbt って?・ドキュメント   http://www.scala-sbt.org/・ BuildTool です  ant とかと一緒・ 設定ファイルが xml じゃなくて scala のコード・ 依存ライブラリの追加が簡単・ scala のバージョンが異なるプロジェクトの管理が楽
  • ここからはみんなで!・ sbt で log4j つかってログを吐いてみるバッチを作ってみよう
  • [m_ito@test-a8-mayuyu sbt]$ mkdir ss27[m_ito@test-a8-mayuyu sbt]$ cd ss27/[m_ito@test-a8-mayuyu ss27]$ g8 typesafehub/scala-sbt 時間かかるときありますけScala Project Using sbt ど、 Enter 押すと勝手に答 えちゃうのでじっと我慢!organization [org.example]:name [Scala Project]: log4jprojectscala_version [2.9.2]:version [0.1-SNAPSHOT]:Applied typesafehub/scala-sbt.g8 in log4jproject[m_ito@test-a8-mayuyu ss27]$ cd log4jproject/[m_ito@test-a8-mayuyu log4jproject]$ tree.|-- README|-- project| `-- Log4jprojectBuild.scala`-- src `-- main `-- scala `-- org `-- example `-- Log4jproject.scala6 directories, 3 files
  • [m_ito@test-a8-mayuyu log4jproject]$ sbt run[info] Loading project definition from /home/m_ito/sbt/ss27/log4jproject/project[info] Updating {file:/home/m_ito/sbt/ss27/log4jproject/project/}default-149fc3...[info] Resolving org.scala-sbt#sbt_2.9.1;0.11.3 ......[info] Resolving org.scala-sbt#precompiled-2_9_2;0.11.3 ...[info] Done updating.[info] Compiling 1 Scala source to /home/m_ito/sbt/ss27/log4jproject/project/target/scala-2.9.1/sbt-0.11.3/classes...[info] Set current project to log4jproject (in build file:/home/m_ito/sbt/ss27/log4jproject/)[info] Updating {file:/home/m_ito/sbt/ss27/log4jproject/}log4jproject...[info] Resolving org.scala-lang#scala-library;2.9.2 ...[info] Done updating.[info] Compiling 1 Scala source to /home/m_ito/sbt/ss27/log4jproject/target/scala-2.9.2/classes...[info] Running org.example.Log4jprojectHello, log4jproject[success] Total time: 6 s, completed 2012/11/20 16:12:08[m_ito@test-a8-mayuyu log4jproject]$[m_ito@test-a8-mayuyu log4jproject]$ cat src/main/scala/org/example/Log4jproject.scalapackage org.exampleobject Log4jproject extends App { println("Hello, log4jproject")}[m_ito@test-a8-mayuyu log4jproject]$
  • [m_ito@test-a8-mayuyu log4jproject]$ cat project/Log4jprojectBuild.scalaimport sbt._import sbt.Keys._object Log4jprojectBuild extends Build { lazy val log4jproject = Project( id = "log4jproject", base = file("."), settings = Project.defaultSettings ++ Seq( name := "log4jproject", organization := "org.example", version := "0.1-SNAPSHOT", scalaVersion := "2.9.2", // add other settings here libraryDependencies ++= Seq( コレクションの要素追加し "log4j" %"log4j" % "1.2.16" ) ているので、カンマ忘れず ) に )}[m_ito@test-a8-mayuyu log4jproject]$
  • [m_ito@test-a8-mayuyu log4jproject]$ sbt run[info] Loading project definition from /home/m_ito/sbt/ss27/log4jproject/project[info] Compiling 1 Scala source to /home/m_ito/sbt/ss27/log4jproject/project/target/scala-2.9.1/sbt-0.11.3/classes...[info] Set current project to log4jproject (in build file:/home/m_ito/sbt/ss27/log4jproject/)[info] Updating {file:/home/m_ito/sbt/ss27/log4jproject/}log4jproject...[info] Resolving org.scala-lang#scala-library;2.9.2 ...[info] Resolving log4j#log4j;1.2.16 ...[info] downloading http://repo1.maven.org/maven2/log4j/log4j/1.2.16/log4j-1.2.16.jar ...[info] [SUCCESSFUL ] log4j#log4j;1.2.16!log4j.jar(bundle) (163ms)[info] Done updating.[info] Running org.example.Log4jprojectHello, log4jproject[success] Total time: 2 s, completed 2012/11/20 16:26:16[m_ito@test-a8-mayuyu log4jproject]$ Log4j のダウンロー ドしてくれる
  • [m_ito@test-a8-mayuyu log4jproject]$ cat src/main/scala/org/example/Log4jproject.scalapackage org.exampleimport org.apache.log4j.Logger;object Log4jproject extends App { //println("Hello, log4jproject") val logger: Logger = Logger.getLogger(this.getClass.getName) logger.info("info log test") Log4j 使ってみるコード logger.warn("warn log test") 書いてみる logger.debug("debug log test")}[m_ito@test-a8-mayuyu log4jproject]$ sbt compile[info] Loading project definition from /home/m_ito/sbt/ss27/log4jproject/project[info] Set current project to log4jproject (in build file:/home/m_ito/sbt/ss27/log4jproject/)[info] Compiling 1 Scala source to /home/m_ito/sbt/ss27/log4jproject/target/scala-2.9.2/classes...[success] Total time: 4 s, completed 2012/11/20 16:45:48[m_ito@test-a8-mayuyu log4jproject]$[m_ito@test-a8-mayuyu log4jproject]$ mkdir –p src/main/resources[m_ito@test-a8-mayuyu log4jproject]$ vi src/main/resources/log4j.properties[m_ito@test-a8-mayuyu log4jproject]$ cat src/main/resources/log4j.propertieslog4j.debug=truelog4j.rootCategory=DEBUG, filelog4j.appender.file=org.apache.log4j.FileAppender Log4jproperties をlog4j.appender.file.File=/tmp/test.log 忘れてましたlog4j.appender.file.layout=org.apache.log4j.PatternLayoutlog4j.appender.file.layout.ConversionPattern=%d %-5p %c - %m [%t] (%F:%L)%n[m_ito@test-a8-mayuyu log4jproject]$
  • 動かしてみる[m_ito@test-a8-mayuyu log4jproject]$ sbt run[info] Loading project definition from /home/m_ito/sbt/ss27/log4jproject/project[info] Set current project to log4jproject (in build file:/home/m_ito/sbt/ss27/log4jproject/)[info] Compiling 1 Scala source to /home/m_ito/sbt/ss27/log4jproject/target/scala-2.9.2/classes...[info] Running org.example.Log4jprojectlog4j: Parsing for [root] with value=[DEBUG, file].log4j: Level token is [DEBUG].log4j: Category root set to DEBUGlog4j: Parsing appender named "file".log4j: Parsing layout options for "file".log4j: Setting property [conversionPattern] to [%d [%-5p] %c{1} %M - %m%n].log4j: End of parsing for "file".log4j: Setting property [file] to [/tmp/test.log].log4j: setFile called: /tmp/test.log, truelog4j: setFile endedlog4j: Parsed "file" options.log4j: Finished configuring.[success] Total time: 5 s, completed 2012/11/20 17:39:44 ログ見てみる[m_ito@test-a8-mayuyu log4jproject]$ cat /tmp/test.log2012-11-20 17:45:39,848 INFO org.example.Log4jproject$ - info log test [run-main] (Log4jproject.scala:14)2012-11-20 17:45:39,850 WARN org.example.Log4jproject$ - warn log test [run-main] (Log4jproject.scala:15)2012-11-20 17:45:39,851 DEBUG org.example.Log4jproject$ - debug log test [run-main] (Log4jproject.scala:16)[m_ito@test-a8-mayuyu log4jproject]$
  • まとめSbt 使うと必要なライブラリ落としてきてくれるのでデプロイが楽そう。実行とかのコマンドがみじかくなりますよ。 終わり