Giter Club home page Giter Club logo

sbt-pack's Introduction

sbt-pack plugin

A sbt plugin for creating a distributable Scala package that includes dependent jars and launch scripts.

Features

  • sbt pack creates a distributable package in target/pack folder.
    • All dependent jars including scala-library.jar are collected in target/pack/lib folder. This process is much faster than creating a single-jar as in sbt-assembly or proguard plugins.
    • sbt-pack supports multi-module projects.
    • tar.gz archive generation via sbt pack-archive command.
  • Generates program launch scripts target/pack/bin/{program name}
    • To run the program no need exists to install Scala, since it is included in the lib folder. Only java command needs to be found in the system.
  • sbt pack-archive command creates a tar.gz archive, target/{program name}-{version}.tar.gz.
  • You can install your Scala programs to local machine via cd target/pack; make install. Then you can run the command with ~/local/bin/{program name}
  • You can install multiple versions of your program in the system.
    • The above Makefile script uses a separate folder for each version (e.g., ~/local/{project name}/{project version}).
    • The latest version is linked from ~/local/{project name}/current
  • You can add other resources pack in src/pack folder.
    • All resources in this folder will be copied to target/pack.

Release Notes

  • August 28, 2013 - 0.3.1 release (only for sbt-0.13 or higher)
  • August 21, 2013 - 0.2.4 release (for sbt-0.12.x)
    • Refine log messages
  • August 20, 2013 - 0.2.1 release
    • Add a sample multi-module project
    • Fixes #11, #12
  • May 16, 2013 - Version 0.2 release
    • Stable version
    • Delete only lib folder when make install
  • May 9, 2013 - Version 0.1.10 release
    • Add pack-archive command

Usage

Add sbt-pack plugin to your sbt configuration:

project/plugins.sbt

addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.2.4")  // for sbt-0.12.x

addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.3.1")  // for sbt-0.13.x or higher

Import xerial.sbt.Pack.packSettings into your project settings. Then set packMain variable, a mapping from the your program names to their corresponding main classes. The main classes must be Scala objects that define def main(args:Array[]) method:

project/Build.scala

import sbt._
import sbt.Keys._
import xerial.sbt.Pack._
   
object Build extends sbt.Build {
    
  lazy val root = Project(
    id = "myprog",
    base = file("."),
    settings = Defaults.defaultSettings ++ packSettings ++
    Seq(
      // Specify mappings from program name -> Main class (full package path)
      packMain := Map("hello" -> "myprog.Hello"),
      // Add custom settings here
      // [Optional] JVM options of scripts (program name -> Seq(JVM option, ...))
      packJvmOpts := Map("hello" -> Seq("-Xmx512m")),
      // [Optional] Extra class paths to look when launching a program
      packExtraClasspath := Map("hello" -> Seq("${PROG_HOME}/etc"))
    )
  )
}

src/main/scala/Hello.scala

package myprog
    
object Hello {
  def main(args:Array[String]) = {
    println("Hello World!!")
  }
}

Command Examples

Create a package

$ sbt pack

Your program package will be generated in target/pack folder.

Launch a command

$ target/pack/bin/hello
Hello World!!

Install the command

$ cd target/pack; make install
$ ~/local/bin/hello
Hello World!

Install the command to the system

$ cd target/pack
$ sudo make install PREFIX="/usr/local"
$ /usr/local/bin/hello
Hello World!

Create tar.gz archive of your Scala program package

$ sbt pack-archive

Example projects

See also examples folder in the source code. It contains several Scala project examples using sbt-pack.

Use case

For developers

Creating IntelliJ project:

$ bin/sbt "gen-idea sbt-classifiers"

To test sbt-pack plugin, run

$ bin/sbt scripted

Run a single test project, e.g., src/sbt-test/sbt-pack/multi-module:

$ bin/sbt "scripted sbt-pack/multi-module"

sbt-pack's People

Contributors

xerial avatar mkroli avatar xuwei-k avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.