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
  • start.sh : 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

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/tools/scala/lang/bin
/tools/scala/sbt/bin

3. Env

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

/Users/<your_user>/.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 start.sh 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 start.sh ( on mac ) and give permissions to execute the file via chmod.

APP_HOME=”.”
APP_CLASSPATH=”${APP_HOME}/bin/*:${APP_HOME}/lib/*:${APP_HOME}/ext/*:”
# Print classpath for debugging
echo $APP_CLASSPATH
# 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
:>./start.sh

That is all!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.