Showing posts with label Scala. Show all posts
Showing posts with label Scala. Show all posts

Friday, February 16, 2018

Lagom Scala HelloWorld project

Get started with Lagom using Scala
https://www.lagomframework.com/get-started-scala.html

Create project and add it to GitHub
https://developer.lightbend.com/start/?group=lagom&project=lagom-scala-sbt

Lagom Scala project
[dave@localhost github]$ cp ~/Downloads/lagom-scala-sbt.zip .
[dave@localhost github]$ unzip -l lagom-scala-sbt.zip 
Archive:  lagom-scala-sbt.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  02-16-2018 22:19   lagom-scala-sbt/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/src/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/src/main/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/src/main/scala/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/src/main/scala/com/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/src/main/scala/com/example/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/src/main/scala/com/example/hello/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/src/main/scala/com/example/hello/api/
     2864  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-api/src/main/scala/com/example/hello/api/DavescalalagomService.scala
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/scala/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/scala/com/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/scala/com/example/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/scala/com/example/hellostream/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/scala/com/example/hellostream/impl/
     1345  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/scala/com/example/hellostream/impl/DavescalalagomStreamLoader.scala
      551  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/scala/com/example/hellostream/impl/DavescalalagomStreamServiceImpl.scala
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/resources/
      685  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-impl/src/main/resources/application.conf
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/src/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/src/main/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/src/main/scala/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/src/main/scala/com/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/src/main/scala/com/example/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/src/main/scala/com/example/hellostream/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/src/main/scala/com/example/hellostream/api/
      648  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-stream-api/src/main/scala/com/example/hellostream/api/DavescalalagomStreamService.scala
       61  02-16-2018 22:19   lagom-scala-sbt/.sbtopts
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/scala/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/scala/com/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/scala/com/example/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/scala/com/example/hello/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/scala/com/example/hello/impl/
     1642  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/scala/com/example/hello/impl/DavescalalagomServiceImpl.scala
     1648  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/scala/com/example/hello/impl/DavescalalagomLoader.scala
     7007  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/scala/com/example/hello/impl/DavescalalagomEntity.scala
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/resources/
      965  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/main/resources/application.conf
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/scala/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/scala/com/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/scala/com/example/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/scala/com/example/hello/
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/scala/com/example/hello/impl/
     1461  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/scala/com/example/hello/impl/DavescalalagomEntitySpec.scala
     1071  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/scala/com/example/hello/impl/DavescalalagomServiceSpec.scala
        0  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/resources/
      501  02-16-2018 22:19   lagom-scala-sbt/dave-scala-lagom-impl/src/test/resources/logback.xml
        0  02-16-2018 22:19   lagom-scala-sbt/project/
       20  02-16-2018 22:19   lagom-scala-sbt/project/build.properties
      208  02-16-2018 22:19   lagom-scala-sbt/project/plugins.sbt
      118  02-16-2018 22:19   lagom-scala-sbt/.gitignore
      595  02-16-2018 22:19   lagom-scala-sbt/LICENSE
     1514  02-16-2018 22:19   lagom-scala-sbt/build.sbt
      204  02-16-2018 22:19   lagom-scala-sbt/README.md
        0  02-16-2018 22:19   lagom-scala-sbt//
       55  01-15-2018 18:59   lagom-scala-sbt/sbt.bat
       44  01-15-2018 18:59   lagom-scala-sbt/sbt
        0  02-16-2018 22:19   lagom-scala-sbt/sbt-dist/
        0  02-16-2018 22:19   lagom-scala-sbt/sbt-dist/bin/
     6751  01-15-2018 18:59   lagom-scala-sbt/sbt-dist/bin/sbt-launch-lib.bash
     1321  01-15-2018 18:59   lagom-scala-sbt/sbt-dist/bin/sbt.bat
     5062  01-15-2018 18:59   lagom-scala-sbt/sbt-dist/bin/sbt
  1210231  01-15-2018 18:59   lagom-scala-sbt/sbt-dist/bin/sbt-launch.jar
        0  02-16-2018 22:19   lagom-scala-sbt/sbt-dist/conf/
      147  01-15-2018 18:59   lagom-scala-sbt/sbt-dist/conf/sbtconfig.txt
      939  01-15-2018 18:59   lagom-scala-sbt/sbt-dist/conf/sbtopts
---------                     -------
  1247658                     74 files


Add into GitHub
https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

 Generated project
https://github.com/dveselka/lagom-scala-sbt


Build project
[dave@localhost lagom-scala-sbt]$ ./sbt runAll
Getting org.scala-sbt sbt 0.13.16 ...


Check the running service using
http://localhost:9000/api/hello/World



Thursday, April 21, 2016

Scala - setup environment - sbt, Scala IDE

Download sbt http://www.scala-sbt.org/download.html


Configure https proxy
 export JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=webproxy -Dhttp.proxyPort=8080"  


Change sbt repository root
 export _JAVA_OPTIONS='-Duser.home=/d/vesedan/sbt-repository'  


Start sbt
 $ sbt  
 Getting org.scala-sbt sbt 0.13.11 ...  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt/0.13.11/jars/sbt.jar ...  
     [SUCCESSFUL ] org.scala-sbt#sbt;0.13.11!sbt.jar (2209ms)  
 downloading https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.6/scala-library-2.10.6.jar ...  
     [SUCCESSFUL ] org.scala-lang#scala-library;2.10.6!scala-library.jar (36565ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/main/0.13.11/jars/main.jar ...  
     [SUCCESSFUL ] org.scala-sbt#main;0.13.11!main.jar (14438ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-interface/0.13.11/jars/compiler-interface.jar ...  
     [SUCCESSFUL ] org.scala-sbt#compiler-interface;0.13.11!compiler-interface.jar (3732ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/actions/0.13.11/jars/actions.jar ...  
     [SUCCESSFUL ] org.scala-sbt#actions;0.13.11!actions.jar (4983ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/main-settings/0.13.11/jars/main-settings.jar ...  
     [SUCCESSFUL ] org.scala-sbt#main-settings;0.13.11!main-settings.jar (189535ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/interface/0.13.11/jars/interface.jar ...  
     [SUCCESSFUL ] org.scala-sbt#interface;0.13.11!interface.jar (2385ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/io/0.13.11/jars/io.jar ...  
     [SUCCESSFUL ] org.scala-sbt#io;0.13.11!io.jar (3836ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/ivy/0.13.11/jars/ivy.jar ...  
     [SUCCESSFUL ] org.scala-sbt#ivy;0.13.11!ivy.jar (10631ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/logging/0.13.11/jars/logging.jar ...  
     [SUCCESSFUL ] org.scala-sbt#logging;0.13.11!logging.jar (2493ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/logic/0.13.11/jars/logic.jar ...  
     [SUCCESSFUL ] org.scala-sbt#logic;0.13.11!logic.jar (2893ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/process/0.13.11/jars/process.jar ...  
     [SUCCESSFUL ] org.scala-sbt#process;0.13.11!process.jar (3226ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/run/0.13.11/jars/run.jar ...  
     [SUCCESSFUL ] org.scala-sbt#run;0.13.11!run.jar (4793ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/command/0.13.11/jars/command.jar ...  
     [SUCCESSFUL ] org.scala-sbt#command;0.13.11!command.jar (3569ms)  
 downloading https://repo1.maven.org/maven2/org/scala-sbt/launcher-interface/1.0.0-M1/launcher-interface-1.0.0-M1.jar ...  
     [SUCCESSFUL ] org.scala-sbt#launcher-interface;1.0.0-M1!launcher-interface.jar (265ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/classpath/0.13.11/jars/classpath.jar ...  
     [SUCCESSFUL ] org.scala-sbt#classpath;0.13.11!classpath.jar (2508ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/completion/0.13.11/jars/completion.jar ...  
     [SUCCESSFUL ] org.scala-sbt#completion;0.13.11!completion.jar (4228ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/api/0.13.11/jars/api.jar ...  
     [SUCCESSFUL ] org.scala-sbt#api;0.13.11!api.jar (6932ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-integration/0.13.11/jars/compiler-integration.jar ...  
     [SUCCESSFUL ] org.scala-sbt#compiler-integration;0.13.11!compiler-integration.jar (2715ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-ivy-integration/0.13.11/jars/compiler-ivy-integration.jar ...  
     [SUCCESSFUL ] org.scala-sbt#compiler-ivy-integration;0.13.11!compiler-ivy-integration.jar (2659ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/relation/0.13.11/jars/relation.jar ...  
     [SUCCESSFUL ] org.scala-sbt#relation;0.13.11!relation.jar (2618ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/task-system/0.13.11/jars/task-system.jar ...  
     [SUCCESSFUL ] org.scala-sbt#task-system;0.13.11!task-system.jar (2604ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/tasks/0.13.11/jars/tasks.jar ...  
     [SUCCESSFUL ] org.scala-sbt#tasks;0.13.11!tasks.jar (3010ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/tracking/0.13.11/jars/tracking.jar ...  
     [SUCCESSFUL ] org.scala-sbt#tracking;0.13.11!tracking.jar (2193ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/testing/0.13.11/jars/testing.jar ...  
     [SUCCESSFUL ] org.scala-sbt#testing;0.13.11!testing.jar (3076ms)  
 downloading https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.10.6/scala-compiler-2.10.6.jar ...  
     [SUCCESSFUL ] org.scala-lang#scala-compiler;2.10.6!scala-compiler.jar (100258ms)  
 downloading https://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.10.6/scala-reflect-2.10.6.jar ...  
     [SUCCESSFUL ] org.scala-lang#scala-reflect;2.10.6!scala-reflect.jar (10966ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/control/0.13.11/jars/control.jar ...  
     [SUCCESSFUL ] org.scala-sbt#control;0.13.11!control.jar (2203ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/collections/0.13.11/jars/collections.jar ...  
     [SUCCESSFUL ] org.scala-sbt#collections;0.13.11!collections.jar (4384ms)  
 downloading https://repo1.maven.org/maven2/jline/jline/2.13/jline-2.13.jar ...  
     [SUCCESSFUL ] jline#jline;2.13!jline.jar (1690ms)  
 downloading https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.11/jansi-1.11.jar ...  
     [SUCCESSFUL ] org.fusesource.jansi#jansi;1.11!jansi.jar (1058ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/classfile/0.13.11/jars/classfile.jar ...  
     [SUCCESSFUL ] org.scala-sbt#classfile;0.13.11!classfile.jar (2419ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/incremental-compiler/0.13.11/jars/incremental-compiler.jar ...  
     [SUCCESSFUL ] org.scala-sbt#incremental-compiler;0.13.11!incremental-compiler.jar (4280ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compile/0.13.11/jars/compile.jar ...  
     [SUCCESSFUL ] org.scala-sbt#compile;0.13.11!compile.jar (3685ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/persist/0.13.11/jars/persist.jar ...  
     [SUCCESSFUL ] org.scala-sbt#persist;0.13.11!persist.jar (2781ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbinary/sbinary_2.10/0.4.2/jars/sbinary_2.10.jar ...  
     [SUCCESSFUL ] org.scala-tools.sbinary#sbinary_2.10;0.4.2!sbinary_2.10.jar (2939ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/cross/0.13.11/jars/cross.jar ...  
     [SUCCESSFUL ] org.scala-sbt#cross;0.13.11!cross.jar (2050ms)  
 downloading https://repo1.maven.org/maven2/org/scala-sbt/ivy/ivy/2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435c4fa24f9a/ivy-2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435c4fa24f9a.jar ...  
     [SUCCESSFUL ] org.scala-sbt.ivy#ivy;2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435c4fa24f9a!ivy.jar (5077ms)  
 downloading https://repo1.maven.org/maven2/com/jcraft/jsch/0.1.46/jsch-0.1.46.jar ...  
     [SUCCESSFUL ] com.jcraft#jsch;0.1.46!jsch.jar (1399ms)  
 downloading https://repo1.maven.org/maven2/org/scala-sbt/serialization_2.10/0.1.2/serialization_2.10-0.1.2.jar ...  
     [SUCCESSFUL ] org.scala-sbt#serialization_2.10;0.1.2!serialization_2.10.jar (2002ms)  
 downloading https://repo1.maven.org/maven2/org/scala-lang/modules/scala-pickling_2.10/0.10.1/scala-pickling_2.10-0.10.1.jar ...  
     [SUCCESSFUL ] org.scala-lang.modules#scala-pickling_2.10;0.10.1!scala-pickling_2.10.jar (2997ms)  
 downloading https://repo1.maven.org/maven2/org/json4s/json4s-core_2.10/3.2.10/json4s-core_2.10-3.2.10.jar ...  
     [SUCCESSFUL ] org.json4s#json4s-core_2.10;3.2.10!json4s-core_2.10.jar (2953ms)  
 downloading https://repo1.maven.org/maven2/org/spire-math/jawn-parser_2.10/0.6.0/jawn-parser_2.10-0.6.0.jar ...  
     [SUCCESSFUL ] org.spire-math#jawn-parser_2.10;0.6.0!jawn-parser_2.10.jar (699ms)  
 downloading https://repo1.maven.org/maven2/org/spire-math/json4s-support_2.10/0.6.0/json4s-support_2.10-0.6.0.jar ...  
     [SUCCESSFUL ] org.spire-math#json4s-support_2.10;0.6.0!json4s-support_2.10.jar (122ms)  
 downloading https://repo1.maven.org/maven2/org/scalamacros/quasiquotes_2.10/2.0.1/quasiquotes_2.10-2.0.1.jar ...  
     [SUCCESSFUL ] org.scalamacros#quasiquotes_2.10;2.0.1!quasiquotes_2.10.jar (2490ms)  
 downloading https://repo1.maven.org/maven2/org/json4s/json4s-ast_2.10/3.2.10/json4s-ast_2.10-3.2.10.jar ...  
     [SUCCESSFUL ] org.json4s#json4s-ast_2.10;3.2.10!json4s-ast_2.10.jar (774ms)  
 downloading https://repo1.maven.org/maven2/com/thoughtworks/paranamer/paranamer/2.6/paranamer-2.6.jar ...  
     [SUCCESSFUL ] com.thoughtworks.paranamer#paranamer;2.6!paranamer.jar (764ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/cache/0.13.11/jars/cache.jar ...  
     [SUCCESSFUL ] org.scala-sbt#cache;0.13.11!cache.jar (2837ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/test-agent/0.13.11/jars/test-agent.jar ...  
     [SUCCESSFUL ] org.scala-sbt#test-agent;0.13.11!test-agent.jar (2668ms)  
 downloading https://repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar ...  
     [SUCCESSFUL ] org.scala-sbt#test-interface;1.0!test-interface.jar (634ms)  
 downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/apply-macro/0.13.11/jars/apply-macro.jar ...  
     [SUCCESSFUL ] org.scala-sbt#apply-macro;0.13.11!apply-macro.jar (2501ms)  
 :: retrieving :: org.scala-sbt#boot-app  
     confs: [default]  
     49 artifacts copied, 0 already retrieved (17330kB/137ms)  
 Getting Scala 2.10.6 (for sbt)...  
 downloading https://repo1.maven.org/maven2/org/scala-lang/jline/2.10.6/jline-2.10.6.jar ...  
     [SUCCESSFUL ] org.scala-lang#jline;2.10.6!jline.jar (1016ms)  
 downloading https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.4/jansi-1.4.jar ...  
     [SUCCESSFUL ] org.fusesource.jansi#jansi;1.4!jansi.jar (1034ms)  
 :: retrieving :: org.scala-sbt#boot-scala  
     confs: [default]  
     5 artifacts copied, 0 already retrieved (24494kB/62ms)  
 [info] Set current project to sbt (in build file:/D:/vesedan/sbt/)  


Start Scala console
 > console  
 [info] Updating {file:/D:/vesedan/sbt/}sbt...  
 [info] Resolving org.fusesource.jansi#jansi;1.4 ...  
 [info] Done updating.  
 [info] 'compiler-interface' not yet compiled for Scala 2.10.6. Compiling...  
 [info]  Compilation completed in 16.541 s  
 [info] Starting scala interpreter...  
 [info]  
 Welcome to Scala version 2.10.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_74).  
 Type in expressions to have them evaluated.  
 Type :help for more information.  
 scala>  
 scala>  
 scala> println("Hi!")  
 Hi!
 scala>  

Download  Scala IDE
 http://scala-ide.org/download/sdk.html

Tuesday, November 10, 2015

Create new Scala Maven project for Eclipse

Scala with Maven tutorial
http://docs.scala-lang.org/tutorials/scala-with-maven.html

Download latest version of Scala http://www.scala-lang.org/download/2.11.7.html

Upgrade Scala version

[root@localhost Downloads]# dnf  upgrade  scala-2.11.7.rpm


Create Scala Maven project from archetype using

   mvn archetype:generate

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 686: scala
Choose archetype:
1: remote -> co.cask.cdap:cdap-spark-scala-archetype (-)
2: remote -> com.github.igor-petruk.archetypes:maven-archetype-scala-executable (Creates executable Scala Project that is ready to run with 'java -jar')
3: remote -> de.schlichtherle:javafx-scala-demo (An archetype for a standalone JavaFX 2.0 application written in Scala.
The generated application is translated from the Colorful Circles demo from the
JavaFX 2.0 SDK.)
4: remote -> eu.stratosphere:quickstart-scala (-)
5: remote -> net.alchim31.maven:scala-archetype-simple (The maven-scala-plugin is used for compiling/testing/running/documenting scala code in maven.)
6: remote -> net.ladstatt:scala-javafx-archetype (The Scala JavaFX Archetype provides a simple template for a scala based 
    JavaFX project)
7: remote -> org.apache.camel.archetypes:camel-archetype-component-scala (Creates a new Camel component with Scala.)
8: remote -> org.apache.camel.archetypes:camel-archetype-scala (Creates a new Camel project using Scala DSL.)
9: remote -> org.apache.flink:flink-quickstart-scala (-)
10: remote -> org.fusesource.scalate.tooling:scalate-archetype-empty (An archetype which creates an empty Scalate web application)
11: remote -> org.fusesource.scalate.tooling:scalate-archetype-guice (An archetype which creates an empty Scalate Guice web application)
12: remote -> org.fusesource.scalate.tooling:scalate-archetype-guice_2.10 (An archetype which creates an empty Scalate Guice web application)
13: remote -> org.fusesource.scalate.tooling:scalate-archetype-guice_2.9 (An archetype which creates an empty Scalate Guice web application)
14: remote -> org.fusesource.scalate.tooling:scalate-archetype-jersey (An archetype which creates an empty Scalate web application)
15: remote -> org.fusesource.scalate.tooling:scalate-archetype-jersey_2.10 (An archetype which creates an empty Scalate web application)
16: remote -> org.fusesource.scalate.tooling:scalate-archetype-jersey_2.9 (An archetype which creates an empty Scalate web application)
17: remote -> org.fusesource.scalate.tooling:scalate-archetype-sitegen (An archetype which creates an empty Scalate static website generation project)
18: remote -> org.fusesource.scalate.tooling:scalate-archetype-sitegen_2.10 (An archetype which creates an empty Scalate static website generation project)
19: remote -> org.fusesource.scalate.tooling:scalate-archetype-sitegen_2.9 (An archetype which creates an empty Scalate static website generation project)
20: remote -> org.openjdk.jmh:jmh-scala-benchmark-archetype (Generates Scala benchmarking project, uses JMH bytecode processors)
21: remote -> org.scala-tools.archetypes:scala-archetype-simple (The maven-scala-plugin is used for compiling/testing/running/documenting scala code in maven.)
22: remote -> org.scalatra.scalate.tooling:scalate-archetype-guice_2.10 (An archetype which creates an empty Scalate Guice web application)
23: remote -> org.scalatra.scalate.tooling:scalate-archetype-guice_2.11 (An archetype which creates an empty Scalate Guice web application)
24: remote -> org.scalatra.scalate.tooling:scalate-archetype-jersey_2.10 (An archetype which creates an empty Scalate web application)
25: remote -> org.scalatra.scalate.tooling:scalate-archetype-jersey_2.11 (An archetype which creates an empty Scalate web application)
26: remote -> org.scalatra.scalate.tooling:scalate-archetype-sitegen_2.10 (An archetype which creates an empty Scalate static website generation project)
27: remote -> org.scalatra.scalate.tooling:scalate-archetype-sitegen_2.11 (An archetype which creates an empty Scalate static website generation project)
28: remote -> org.wicketstuff.scala:wicket-scala-archetype (Basic setup for a project that combines Scala and Wicket, 
        depending on the Wicket-Scala project. Includes an example Specs 
        test.)
29: remote -> org.wicketstuff.scala:wicketstuff-scala-archetype (Basic setup for a project that combines Scala and Wicket, 
        depending on the Wicket-Scala project. Includes an example Specs 
        test.)
30: remote -> pl.org.miki:scala-quickstart-archetype (Customizable cruft-free Scala archetype. Options:
-sourceFolders: [all-in-src-java, scala-only, both-split-src]. DEFAULT: all-in-src-java.
--all-in-src-java: Scala and Java code are both in src/main/java (same for test). Plays nicely with IDEs.
--scala-only: only src/main/scala set up, and set as source folder.
--both-split-src: both src/main/java and src/main/scala. Can play merry havock with IDEs, so not the default.
-testLibrary: [scalatest, specs2, scalacheck-only, junit-only]. DEFAULT: scalatest.
--scalatest: adds Scalatest AND Scalacheck AND JUnit for most of your testing needs.
--specs2: adds specs2 AND Scalacheck AND JUnit.
--scalacheck-junit: adds Scalacheck AND JUnit.
--junit-only: adds JUnit ONLY.
-scalaVersion: 2.10.x+. DEFAULT: 2.11.2.
*The Scala tool version is generated automatically.
*Some Scala versions may not be compatible with selected test library versions. Adjust as necessary.)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 

Choose simple archetype ( number 5 or 30 )

https://github.com/mikolak-net/scala-quickstart-archetype 

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 5
Choose net.alchim31.maven:scala-archetype-simple version: 
1: 1.4
2: 1.5
3: 1.6
Choose a number: 3: 3
Downloading: http://maven.repository.redhat.com/earlyaccess/all/net/alchim31/maven/scala-archetype-simple/1.6/scala-archetype-simple-1.6.jar
Downloading: http://maven.repository.redhat.com/techpreview/all/net/alchim31/maven/scala-archetype-simple/1.6/scala-archetype-simple-1.6.jar
Downloading: https://repo.maven.apache.org/maven2/net/alchim31/maven/scala-archetype-simple/1.6/scala-archetype-simple-1.6.jar
Downloaded: https://repo.maven.apache.org/maven2/net/alchim31/maven/scala-archetype-simple/1.6/scala-archetype-simple-1.6.jar (5 KB at 16.5 KB/sec)
Downloading: http://maven.repository.redhat.com/earlyaccess/all/net/alchim31/maven/scala-archetype-simple/1.6/scala-archetype-simple-1.6.pom
Downloading: http://maven.repository.redhat.com/techpreview/all/net/alchim31/maven/scala-archetype-simple/1.6/scala-archetype-simple-1.6.pom
Downloading: https://repo.maven.apache.org/maven2/net/alchim31/maven/scala-archetype-simple/1.6/scala-archetype-simple-1.6.pom
Downloaded: https://repo.maven.apache.org/maven2/net/alchim31/maven/scala-archetype-simple/1.6/scala-archetype-simple-1.6.pom (4 KB at 33.7 KB/sec)
Define value for property 'groupId': : scala
Define value for property 'artifactId': : class-finder
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  scala: : dave
Confirm properties configuration:
groupId: scala
artifactId: class-finder
version: 1.0-SNAPSHOT
package: dave
 Y: : 


Created project
[dave@localhost scala]$ find 
.
./class-finder
./class-finder/pom.xml
./class-finder/.gitignore
./class-finder/src
./class-finder/src/main
./class-finder/src/main/scala
./class-finder/src/main/scala/dave
./class-finder/src/main/scala/dave/App.scala
./class-finder/src/test
./class-finder/src/test/scala
./class-finder/src/test/scala/samples
./class-finder/src/test/scala/samples/junit.scala
./class-finder/src/test/scala/samples/specs.scala
./class-finder/src/test/scala/samples/scalatest.scala



Add into pom.xml  the build-helper-maven-plugin to add new source folders as described here http://docs.scala-lang.org/tutorials/scala-with-maven.html

Import existing  Maven  project into Eclipse

Edit .project and .classpath files to include Scala

Optionally
  -- Run mvn eclipse:eclipse in project dir
  --- Configure Eclipse workspace

dave@localhost class-finder]$ mvn -Declipse.workspace="/home/dave/workspace/scala"  eclipse:configure-workspace

.project

[dave@localhost class-finder]$ more .project 
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>class-finder</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.scala-ide.sdt.core.scalabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.scala-ide.sdt.core.scalanature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
    </natures>
</projectDescription>

.classpath

[dave@localhost class-finder]$ more .classpath 
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMTyp
e/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/classes" path="src/main/scala">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/scala">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>


pom.xml

[dave@localhost class-finder]$ more pom.xml 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven
.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>scala</groupId>
    <artifactId>class-finder</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <scala.version>2.11.7</scala.version>
        <scala.version.tools>2.11</scala.version.tools>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <!-- this is so we don't end with a compile error in maven-compiler-plugin -->        
                        <phase>process-sources</phase>                     
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                        <configuration>
                            <mainSourceDir>${project.build.sourceDirectory}/../java</mainSourceDir>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/main/scala</source>
                </sources>
            </configuration>
        </execution>
        <execution>
            <id>add-test-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-test-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/test/scala</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>dave.MainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
        </plugin>


        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalacheck</groupId>
            <artifactId>scalacheck_${scala.version.tools}</artifactId>
            <version>1.11.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_${scala.version.tools}</artifactId>
            <version>2.2.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>


Run mvn package 

Open project in Eclipse IDE



Add launcher for command line
<build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
      <launchers>
        <launcher>
          <id>foo</id>
          <mainClass>dave.App</mainClass>
          <!-- args are optional -->
          <args>
            <arg>arg1</arg>
          </args>
          <!-- jvmArgs are optional -->
          <jvmArgs>
            <jvmArg>-Xmx128m</jvmArg>
            <jvmArg>-Djava.library.path=...</jvmArg>
          </jvmArgs>
        </launcher>
        <!-- you could define other launcher -->
      </launchers>
    </configuration>


Run project  from command line


mvn scala:run

[INFO] launcher 'foo' selected => dave.App
Hello World!
concat arguments = arg1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------


Known errors

http://scala-ide.org/docs/current-user-doc/faq/index.html#Know_Issue

Add m2e-scala http://alchim31.free.fr/m2e-scala/update-site/

If you see errors in using prototype modify the pom.xml

[INFO] /home/dave/git/scala/class-finder/src/main/scala:-1: info: compiling
[INFO] Compiling 1 source files to /home/dave/git/scala/class-finder/target/classes at 1447218248818
[ERROR] scalac error: bad option: '-make:transitive'


see here http://stackoverflow.com/questions/12812458/getting-started-with-scala-scalatest-and-maven

Try to change versions in pom.xml or  change options for scala-maven-plugin

https://github.com/davidB/scala-maven-plugin
  

https://github.com/scala/scala-module-dependency-sample/blob/master/maven-sample/pom.xml


Error related to versions of Scala artifacts - change the repository configuration
[ERROR] Failed to execute goal on project class-finder: Could not resolve dependencies for project scala:class-finder:jar:1.0-SNAPSHOT: Could not find artifact org.scalaz.stream:scalaz-stream_2.11:jar:0.7a in jboss-earlyaccess-repository (http://maven.repository.redhat.com/earlyaccess/all/) -> [Help 1]

Tuesday, October 9, 2012

Mixed Java and Scala development in Eclipse

.classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.inter
nal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

.project file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>testScala</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.scala-ide.sdt.core.scalabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.scala-ide.sdt.core.scalanature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>


TestPerson.scala class
package dave

object  TestPerson {
  def main(args: Array[String]) {
    val person = new Person("dave")

    println(person)
  }
}

Person.java class
package dave;

public class Person {
    
    String name;
    
    public Person() {}
    
    
    public Person(String name) {
        this.name= name;
    }
    
    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }


    @Override
    public String toString() {
        return "Person [name=" + name + "]";
    }

    
    
}
Eclipse with Scala plugin
Java buildpath
All files in project
[dave@dave testScala]$ ls -lRa
.:
total 32
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:41 .
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:04 ..
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:41 bin
-rw-rw-r--. 1 dave dave 2222 Oct  9 22:51 .cache
-rw-rw-r--. 1 dave dave  376 Oct  9 22:04 .classpath
-rw-rw-r--. 1 dave dave  425 Oct  9 22:04 .project
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:40 .settings
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:04 src

./bin:
total 12
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:41 .
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:41 ..
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:51 dave

./bin/dave:
total 20
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:51 .
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:41 ..
-rw-rw-r--. 1 dave dave  821 Oct  9 22:41 Person.class
-rw-rw-r--. 1 dave dave  648 Oct  9 22:51 TestPerson.class
-rw-rw-r--. 1 dave dave  706 Oct  9 22:51 TestPerson$.class

./.settings:
total 16
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:40 .
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:41 ..
-rw-rw-r--. 1 dave dave  587 Oct  9 22:04 org.eclipse.jdt.core.prefs
-rw-rw-r--. 1 dave dave  847 Oct  9 22:40 org.scala-ide.sdt.core.prefs

./src:
total 12
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:04 .
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:41 ..
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:20 dave

./src/dave:
total 16
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:20 .
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:04 ..
-rw-rw-r--. 1 dave dave  328 Oct  9 22:25 Person.java
-rw-rw-r--. 1 dave dave  131 Oct  9 22:51 TestPerson.scala
[dave@dave testScala]$