3
votes

Is it possible to use the sbt-assembly and sbt-native-packager plugins to create a java application archetype installation that instead of having the project jar and its dependencies in <app>/lib contains just the assembly jar?

I've built a Spark application and I want to add the assembly to the context rather than adding each jar individually.

Edit: I need to build deb packages for deployment. I want the deb package to contain the assembly not the project & dependent jars.

The filesystem layout should be

<install_dir>
     bin
         appname
     conf
         application.conf
     lib
         appname-assembly.jar

sbt-native-packager adds a symlink to /usr/bin which is convenient but not necessary.

2
Can you add the expected deb package layout and how do the files relate to the project?Jacek Laskowski
edited question to add the file layoutdkorz

2 Answers

1
votes

This is possible with native package. A full example can be found on github You have to change the mappings and the scriptClasspath

Your build.sbt should contain the following parts

// the assembly settings
assemblySettings

// we specify the name for our fat jar
jarName in assembly := "assembly-project.jar"

// using the java server for this application
packageArchetype.java_server

maintainer in Linux := "Nepomuk Seiler <[email protected]>"

packageSummary in Linux := "Custom application configuration"

packageDescription := "Custom application configuration"

// removes all jar mappings in universal and appends the fat jar
mappings in Universal := {
    // universalMappings: Seq[(File,String)]
    val universalMappings = (mappings in Universal).value 
    val fatJar = (assembly in Compile).value
    // removing means filtering
    val filtered = universalMappings filter { 
        case (file, name) =>  ! name.endsWith(".jar") 
    }
    // add the fat jar
    filtered :+ (fatJar -> ("lib/" + fatJar.getName))
0
votes

It appears that the sbt-onejar plugin could be of help (instead of relying on the other plugins - sbt-assembly and sbt-native-packager):

sbt-onejar is a simple-build-tool plugin for building a single executable JAR containing all your code and dependencies as nested JARs.