This weekend I took some baby steps in scala.  The [ultimate] target is to learn scala and to build a cool folder synchronizer in scala that will work fast and furious in keeping remote folders in synch.


svn checkout foldersync

From what I understod so far, scala is an excellent language improvement over java. The code one writes in scala gets compiled into .class files in the byte code format. This mechanism makes compiled scala indistinguishable from Java. In my case this was the ‘Gotcha’ moment and armed with this knowledge I was able to setup the development environment just the way I wanted it.

  • Can build and test scala with maven2
  • Can write testcases for scala code not only in scala but in java also(Vice Versa also true).
  • Can use a batch file to run the final artifact.
  • Can be packaged with an IzPack installer (Installer can be invoked right within Maven2, nothing specific to scala though).

Important Tools:

  1. Scala IDE for Eclipse
  2. scala-maven-plugin
  3. izpack-maven-plugin

Using the scala-maven-plugin I could extend the standard maven2 code layout into scala with src/main/scala for scala code and src/test/scala for testcases in scala.  Another important aspect is java code can coexist.  In my case I follwed the recommendation from the plugin and used src/main/java and src/test/java.


Another great feature of this tool is it’s complete self sufficient nature in it’s relationship with the scala compiler.  It locates the scala compiler through the maven dependency tree.


The fun part was realizing you could write testcases in Java or in Scala.

import org.junit.Test;
import static org.junit.Assert.*;
public class JavaFolderTest {
	public void testCreateJavaFolder(){
		assertNotNull(new Folder());

	public void testCreateScalaFolder(){
		org.boni.scala.foldersync.domain.Folder folder = new org.boni.scala.foldersync.domain.Folder();
package org.boni.scala.foldersync.domain
import org.junit._
import Assert._
class ScalaFolderTest {
	def testCreateJavaFolder(){

	def testCreateScalaFolder(){
		assertNotNull(new org.boni.scala.foldersync.domain.Folder());

While writing code is fun you would expect a solid transport for packaging and deploying your final product. IzPack came in handy with it’s amazingly simple yet powerful xml driven install scripts – needless to say but it worked perfectly fine with the scala classes and with the maven build process. For this project I wanted a simple batch file based invocation system that will appropriately modify the libraries it needs and then invoke the class with the main.

package org.boni.scala.foldersync.runner

object FolderSynchronizer {
	def main(args: Array[String]){
	  println("Starting folder synchronizer...");

The build process I hacked together copies all the necessary dependencies and the other files I need as part of the installation (README, License, Documents) to a staging folder. Then it invokes the IzPack installer plugin that packages everything together as directed in a install.xml script. It also packages along the batch file I want to run and in addition it modifies the batch file to substitute some variables with actual installation conditions. The installer can be invoked by typing java -jar [folder-sync-standard.jar]

Once installed, user should be able to run the application through command line by typing run.bat. The complete build including the installer creation is driven through maven life cycle.

In the coming days as I learn more scala I intend to extend this rudimentary framework to a full scale folder synchronizer implementation in scala.  Will be updating the progress.  Stay tuned on both wordpress and  google code.

One Thought on “Learning Scala

  1. Hi
    The IzPack installer plugin that you mention: is that based on SBT?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation