jorjor17
jorjor17

Reputation: 21

Possible to compile and run scala-akka scripts from command-line without build tools like sbt?

I am a beginner learning to program in scala-akka and I have had no problems running my scripts on IntelliJ IDE / and 'sbt run'. However, I can't seem to find any resources that teaches me how to manually use scalac and the akka jar dependency to compile and run just from the command-line. Can anyone point me in the right direction?

Upvotes: 0

Views: 231

Answers (2)

Leo C
Leo C

Reputation: 22449

Let's assume you have Scala and Akka installed somewhere under /home/leo/apps/ and Scala binaries are searchable (e.g. export PATH=$PATH:home/leo/apps/scala-2.11.8/bin)

Next, let's say you have a Scala main app Tweets.scala along with a few supplementary classes packaged in akkastreams under /home/leo/myproject/:

akkastreams/
  Tweets.scala
  Author.scala
  HashTag.scala
  Message.scala
  ...

Here's how you'll compile and run the app:

cd /home/leo/myproject/

# Compile all files in package akkastreams:
scalac -cp "/home/leo/apps/akka-2.4.9/lib/akka/*" akkastreams/*.scala

# Run the main app Tweets (object Tweets extends App):
# Note that classpath includes also current subdir '.'
scala -cp "/home/leo/apps/akka-2.4.9/lib/akka/*:." akkastreams.Tweets

A few notes:

  1. You could include only specific Akka jars instead of all of them.
  2. Without dependencies and versioning being managed by sbt, you'll need to manually maintain version consistency between Scala's bundled Akka libraries versus Akka's own ones.
  3. While it's a good exercise to see how things are done in a crude way, it's obviously unproductive to do this on a regular basis.

Upvotes: 1

Bartek
Bartek

Reputation: 134

In my opinion You should perform scalac and scala with classpath parameter and selected library jar file.

By the way it's still more convenient to use sbt.

Upvotes: 0

Related Questions