user835956
user835956

Reputation: 43

scala : create jar from scala files

I have a bunch of Scala files, java files. The Scala files depend on 1 external Scala jar. Now, how do I create a jar out of this ?

I am a newbie to Scala. Could you list out step by step procedure for creating the jar ? I am not working with any IDEs and currently working from Linux Terminal

Thanks in Advance.

Upvotes: 1

Views: 231

Answers (1)

Mikaël Mayer
Mikaël Mayer

Reputation: 10681

Personally, I'm using one-jar with sbt; so that it includes scala libraries automatically. You need to have one main class for that.

  1. Install sbt on your machine http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html
  2. Put all your scala sources to src/main/scala and your java files to src/main/java
  3. Create a folder project/
  4. Add a file named plugins.sbt into it.
  5. Somewhere, install the one-jar plugin with the instructions: https://github.com/sbt/sbt-onejar
  6. Add the line addSbtPlugin("org.scala-sbt.plugins" % "sbt-onejar" % "0.8") to plugins.sbt of your main project
  7. create a file named build.sbt and fill it with the following:

build.sbt:

name := "Application name"

version := "1.0" // your version number

organization := "ch.epfl.lara" // your organisation or package name

scalaVersion := "2.10.2" // The scala version used

seq(com.github.retronym.SbtOneJar.oneJarSettings: _*)

libraryDependencies += "commons-lang" % "commons-lang" % "2.6"

mainClass in oneJar := Some("YOUR.PACKAGE.AND.MAINCLASS")

Now run sbt one-jar in command line in your directory and voilà!

Upvotes: 1

Related Questions