run

How to compile, run, and package a Scala project with SBT

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.2, “How to compile, run, and package a Scala project with SBT.”

Back to top

Problem

You want to use SBT to compile and run a Scala project, and package the project as a JAR file.

Back to top

Solution

Create a directory layout to match what SBT expects, then run sbt compile to compile your project, sbt run to run your project, and sbt package to package your project as a JAR file.

Table of Contents

  1. Problem
  2. Solution
Back to top

How to compile Scala code with ‘scalac’ and run it with ‘scala’

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.5, “How to compile Scala code with 'scalac' and run it with 'scala'.”

Problem

Though you normally use the Simple Build Tool (SBT) to build Scala applications, you may want to use more basic tools to compile and run small test programs, in the same way you might use javac and java with small Java applications.

How to start a Scala/Akka Actor

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 13.5, “How to start a Scala/Akka Actor.”

Problem

You want to start an Akka actor, or attempt to control the start of an actor.

Scala - An index of methods to run/execute external system commands

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.20, “An index of methods available to run external system commands.”

The following tables list the methods of the scala.sys.process package that you can use when running external (system) commands.

Methods to execute external commands

Table 12-1 lists the methods that you can use to execute system commands.

Table 12-1. Methods to execute system commands

Setting a Scala application's command line parameters in Eclipse

I’ve been developing a new Scala application named Cato that requires some command-line parameters, and I just had to figure out how to configure Eclipse so my application would get those parameters. Doing this with Scala in Eclipse is different than configuring Java command line parameters in Eclipse, so I thought I’d share the recipe.

Fortunately it’s just a two-step process. First, click the drop-down icon next to the “Run” button and choose “Run Configurations”, as shown here:

Java directories - How to determine the directory your Java application was started in

If you ever need to determine what directory your Java code is being run from (essentially the current working directory), you can get this information from the system properties, specifically the System.getProperty or System.getProperties methods.

The following line of Java code shows how to determine what directory your Java application was started in. This information is stored in the user.dir system property, which you access like this:

MySQL: How to start a MySQL server and client on a non-standard port

MySQL shell scripts and port FAQ: Can you share some MySQL examples that show how to start MySQL on a non-standard port (non default port)?

For a variety of reasons you may want or need to run your MySQL server on a different port than the default MySQL port of 3306. In those cases the easiest thing you can do is create a Unix/Linux shell script to start your MySQL server on some other port.