Getting Started
In this tutorial, you’ll see how to create a Scala/Java project using a giter8 template for CSW (csw.g8) which contains sample handlers for creating HCD and Assembly. It also contains a deploy project which is responsible for starting multiple components or containers. You can use this as a starting point for your own projects for writing component. We’ll use the sbt build tool which compiles, runs, and tests your projects among other related tasks.
Installation
Supported Operating Systems are: CentOS and MacOS
- Make sure you have the Java 8 JDK (also known as 1.8)
- Run
javac -version
in the command line and make sure you seejavac 1.8.___
- If you don’t have version 1.8 or higher, install the JDK
- Run
- Install sbt
- Install IntelliJ
- Install following IntelliJ Plugins
- Recommended testing frameworks/tools:
Create project
cd
to an empty folder.- Run the following command
sbt new tmtsoftware/csw.g8
. This pulls the ‘csw’ template from GitHub. If above command fails to pull template, then try running with full pathsbt new https://github.com/tmtsoftware/csw.g8
- Provide input details when prompted. Follow the template readme.md for detailed information about input parameters.
To open the project in IntelliJ, start IntelliJ and click on Import Project in the Intro dialog. If you have a project already open, click on File -> New -> Project from Existing Sources…
Then select the directory created by the template and click Open.
You will then see a dialog asking how to import the project.
Be sure the Import project from external model radio button and sbt options are selected and click Next. Then click Finish on the next dialog to accept the defaults.
Let’s take a look at what just got generated:
In this example, a project was created with default parameters. The complete project structure looks like this:
- As you can see in below snapshot, template will create three projects:
sample-assembly
sample-hcd
sample-deploy
sample-deploy
project is used to create a concrete implementation. This allows for the construction of a complete binary package bundled with all dependencies, and a launching application.
3. Template comes with
csw
and other useful library dependencies. It also includes bunch of plugins as explained in below snapshot
Add new sbt project module
If you want to add another component to the project, for example, with the name sample-io
, you have to create a new sbt module:
-
Add external library dependencies required by
sample-io
inLibs.scala
file, if it does not exist.val `akka-actor` = "com.typesafe.akka" %% "akka-actor" % "2.5.11"
-
Map new/existing library dependencies in
Dependencies.scala
file against new project.val SampleIO = Seq( Libs.`akka-actor` )
-
Include below snippet in
build.sbt
file, this will create new sbt project module.lazy val `sample-io` = project .settings( libraryDependencies ++= Dependencies.SampleIO )
-
If your new module depends on code from other modules within this project, use
.dependsOn
in your build.sbt file:lazy val `sample-io` = project .settings( libraryDependencies ++= Dependencies.SampleIO ) .dependsOn( `sample-assembly`, `sample-hcd` )
-
Update the deployment dependencies:
lazy val `sample-deploy` = project .dependsOn( `sample-assembly`, `sample-hcd`, `sample-io` )