18

The answer: Making stand-alone jar with Simple Build Tool seems like what I need, but it did not have enough information for me, so this is a followup.

(1) How do I adapt the answer to my need? I don't understand what would need to be changed.

(2) What command do I run to create the standalone jar?

(3) Where can I find the jar after it has been created?


What I've tried:

  • Pasting the code in the linked answer verbatim into my: project/build/dsg.scala file. The file now has a

    class ForkRun(info: ProjectInfo) extends DefaultProject(info)

    (from before, used for running projects in a separate VM from SBT) and the new:

    trait AssemblyProject extends BasicScalaProject

    from the linked answer.

  • I also tried pasting the body (all defs and the lazy val of the AssemblyProject into the body of ForkRun.

To create a jar I ran package at the SBT prompt and get:

[info] Packaging ./target/scala_2.8.1/dsg_2.8.1-1.0.jar ...
[info] Packaging complete.

So I tried running the dsg_2.8.1-1.0.jar from the shell via:

java -jar dsg_2.8.1-1.0.jar 

But I get:

Failed to load Main-Class manifest attribute from
dsg_2.8.1-1.0.jar

Could this be caused by having multiple entry points into my project? I select from a list when I execute run from the SBT prompt. Perhaps I need to specify the default when creating the package?

Community
  • 1
  • 1
dsg
  • 12,924
  • 21
  • 67
  • 111
  • 1
    I have edited my answer from 2010 (http://stackoverflow.com/questions/2887655/making-stand-alone-jar-with-simple-build-tool/2887681#2887681) to include retronym's sbt-onejar plugin. – VonC May 17 '11 at 07:00
  • possible duplicate of [How do I run an sbt main class from the shell as normal command-line program?](http://stackoverflow.com/questions/7134993/how-do-i-run-an-sbt-main-class-from-the-shell-as-normal-command-line-program) – Jacek Laskowski Dec 28 '13 at 20:45
  • Duplicate of http://stackoverflow.com/q/7134993/1305344 and http://stackoverflow.com/q/7195079/1305344 – Jacek Laskowski Dec 28 '13 at 20:45

2 Answers2

7

Here's a writeup I did on one way to make an executable jar with SBT:

http://janxspirit.blogspot.com/2011/01/create-executable-scala-jar-with-sbt.html

Janx
  • 3,285
  • 3
  • 19
  • 24
  • Thanks. Turns out that I was not: (1) setting the default entry point via `override def mainClass: Option[String] = Some("Test")` (2) running the `assembly` task (instead of `package`) and (3) running the wrong executable, the correct one is `target/scala_2.8.1/dsg_2.8.1-assembly-1.0.jar` – dsg May 17 '11 at 05:10
1

sbt-assembly is a sbt plugin to create a standalone jar of Scala sbt project with all of its dependencies.

Refer this post for more details with an example.

prabeesh
  • 935
  • 9
  • 11