Running Scala on Linux / Mac

This is a short how-to guide on getting Scala setup and running on Linux / Mac.

1. Folders

Assume I have the following folder structure for you built application

  • bin : all application specific jars
  • conf : the conf files for your application
  • ext : external 3rd party jars
  • lib : core scala libraries
  • : the run script for your appl ( bash script )

2. Paths

Ensure java and/or scala are in the path ( depending on whether you want to run your Scala apps using Scala or simply Java ), file located /etc/paths


3. Env

If you want any environment variables available to your profile for your bash scripts. Set them up in the .bash_profile


export JAVA_HOME=/Library/Java/JVM/jdk1.8.0_101/Contents/Home
export SBT_HOME=/tools/scala/sbt/bin

4. Script

Now create your script in the root of your application folder to run your application. Example below using Java to run your Scala app. This simply adds the bin, lib, ext folders to the classpath and runs java

Ensure you have unlocked your ( on mac ) and give permissions to execute the file via chmod.

# Print classpath for debugging
# Use java to run scala app ( set classpath and supply main class )
java -cp “${APP_CLASSPATH}” sampleapp.Sample1

5. Run

You should be good to go now! Open up your terminal and cd to the root folder of your application and ru

:>cd /dev/apps/scala/sample1

That is all!