run

SBT: How to pass command line arguments to ‘sbt run’ alvin August 17, 2017 - 11:30am

Question: How do I pass command-line parameters to my Scala application when I’m running the application with SBT?

Solution: There are two different possible scenarios here:

How to resolve SBT problems by generating a stack trace

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.12, “Resolving Problems by Getting an SBT Stack Trace.”

Problem

In a Scala project, you’re trying to use SBT to compile, run, or package a project, and it’s failing, and you need to be able to see the stack trace to understand why it’s failing.

Scala/SBT: How to specify a main method/class to run

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.9, “Specifying a Main Class to Run with SBT.”

Problem

In a Scala SBT project, you have multiple main methods in objects in your project, and you want to specify which main method should be run when you type sbt run, or specify the main method that should be invoked when your project is packaged as a JAR file.

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: