Repository: sbt/sbt-onejar Branch: master Commit: f779a478a471 Files: 29 Total size: 14.5 KB Directory structure: gitextract_l534a0k4/ ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.sbt ├── notes/ │ ├── 0.1.markdown │ ├── 0.2.markdown │ ├── 0.3.markdown │ ├── 0.4.markdown │ ├── 0.5.markdown │ ├── 0.6.markdown │ └── about.markdown ├── project/ │ ├── build.properties │ └── plugins.sbt └── src/ ├── main/ │ ├── resources/ │ │ ├── one-jar-boot-0.97.jar │ │ ├── one-jar-boot-0.98.jar │ │ └── one-jar-license.txt │ ├── scala/ │ │ └── com/ │ │ └── github/ │ │ └── retronym/ │ │ └── SbtOneJar.scala │ ├── scala-sbt-0.13/ │ │ └── com/ │ │ └── github/ │ │ └── retronym/ │ │ └── Compat.scala │ └── scala-sbt-1.0/ │ └── com/ │ └── github/ │ └── retronym/ │ └── Compat.scala └── sbt-test/ └── one-jar/ ├── basic/ │ ├── build.sbt │ ├── project/ │ │ └── plugins.sbt │ ├── src/ │ │ └── main/ │ │ └── scala/ │ │ └── basic/ │ │ └── basic.scala │ └── test └── multi/ ├── alpha/ │ └── src/ │ └── main/ │ └── scala/ │ └── alpha/ │ └── alpha.scala ├── beta/ │ └── src/ │ └── main/ │ └── scala/ │ └── beta/ │ └── beta.scala ├── build.sbt ├── project/ │ └── plugins.sbt └── test ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ syntax: glob lib_managed project/boot src_managed target classes .idea/workspace.xml .idea/ant.xml .DS_Store *~ .idea .idea_modules .lib .ivy .boot ================================================ FILE: .travis.yml ================================================ language: scala sudo: false jdk: oraclejdk8 script: - sbt test "^ scripted" before_cache: - find $HOME/.sbt -name "*.lock" | xargs rm - find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm cache: directories: - $HOME/.ivy2/cache - $HOME/.sbt/launchers ================================================ FILE: LICENSE ================================================ Copyright (c) 2010-2011 Coda Hale Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # sbt-onejar: Package your project using [One-JAR™](http://one-jar.sourceforge.net)* sbt-onejar is a [simple-build-tool](http://github.com/harrah/xsbt/wiki) plugin for building a single executable JAR containing all your code and dependencies as nested JARs. Currently One-JAR version 0.9.7 is used. This is included with the plugin, and need not be separately downloaded. ## Requirements Requires SBT 0.12.x, or 0.13.x Users of SBT 0.7.x are directed to the [v0.2](https://github.com/retronym/sbt-onejar/tree/0.2). Currently, you need to include the setting `exportJars := true` if you have a multi-project build. ([Example](https://github.com/retronym/sbt-onejar/blob/master/src/sbt-test/one-jar/multi/project/build.scala#L7)) ## Obtaining Depend on the plugin by editing `project/plugins.sbt`: ``` addSbtPlugin("org.scala-sbt.plugins" % "sbt-onejar" % "0.8") ``` ## Introduce Settings Include the settings from `com.github.retronym.SbtOneJar.oneJarSettings`. You can configure `mainClass in oneJar := Some("com.acme.Woozler")`. It defaults to `mainClass in run in Compile`. Examples * [Light Configuration](https://github.com/retronym/sbt-onejar/blob/master/src/sbt-test/one-jar/basic/build.sbt#L1) * [Full Configuration](https://github.com/retronym/sbt-onejar/blob/master/src/sbt-test/one-jar/multi/project/build.scala#L15) ## Usage run `one-jar` task to generate, erm, one JAR. Run it with `java -jar `. ## What's in the JAR? As an example of the structure, here is the contents of `scalaz-example_2.8.1-5.1-SNAPSHOT-onejar.jar`, a package built from the Scalaz examples module. . |-- META-INF | `-- MANIFEST.MF |-- OneJar.class |-- boot-manifest.mf |-- com | `-- simontuffs | `-- onejar | |-- Boot$1.class | |-- Boot$2.class | |-- Boot$3.class | |-- Boot.class | |-- Handler$1.class | |-- Handler.class | |-- IProperties.class | |-- JarClassLoader$1.class | |-- JarClassLoader$2.class | |-- JarClassLoader$ByteCode.class | |-- JarClassLoader$FileURLFactory$1.class | |-- JarClassLoader$FileURLFactory.class | |-- JarClassLoader$IURLFactory.class | |-- JarClassLoader$OneJarURLFactory.class | |-- JarClassLoader.class | |-- OneJarFile$1.class | |-- OneJarFile$2.class | |-- OneJarFile.class | `-- OneJarURLConnection.class |-- doc | `-- one-jar-license.txt |-- lib | |-- scala-library.jar | |-- scalaz-core_2.8.1-5.1-SNAPSHOT.jar | |-- scalaz-example_2.8.1-5.1-SNAPSHOT.jar | |-- scalaz-geo_2.8.1-5.1-SNAPSHOT.jar | |-- scalaz-http_2.8.1-5.1-SNAPSHOT.jar | `-- servlet-api-2.5.jar |-- main `-- scalaz-example_2.8.1-5.1-SNAPSHOT.jar ## How does it compare to XXX? There are other ways to package your application. I based this plugin on Coda Hale's [sbt-assembly](https://github.com/codahale/assembly-sbt) which builds an über-JAR, directly containing all classes and resources merged together. This approach must be used carefully when there are resources with the same name across multiple JARs. Kris Nuttycombe's [sbt-proguard-plugin](http:github.com/nuttycom/sbt-proguard-plugin) also creates an über-JAR, with the possibility to obfuscate and shrink. This is popular for targeting Android. Proguard is a powerful tool, and it takes some effort to configure it correctly. One-JAR employs some classloader magic to sidestep the über-JAR limitations. It does support classpath scanning, as used in Spring and Hibernate, although there seems to be a performance penalty for this. But if your application, or its libraries, also relies on classloader trickery, you might run into some problems. Caveat Emptor. Looking for something else? One of these might suit: WebStart, Exe4J, jsmooth, izpack. http://stackoverflow.com/questions/1967549/java-packaging-tools-alternatives-for-jsmooth-launch4j-onejar ## Bugs Please report bugs and feature requests to the GitHub issue tracker. Bugs with small sample project will get the most attention. Forks and Pull Requests are also welcome. Problems with One-JAR itself should be reported on it's [Issue Tracker](http://sourceforge.net/tracker/?group_id=111153) ## License Copyright (c) 2011-2011 Jason Zaugg Published under The MIT License, see LICENSE The One-JAR License is reproduced below. This plugin is not endorsed in anyway by One-JAR. >One-JAR (http://one-jar.sourceforge.net). Copyright (c) 2004, >P. Simon Tuffs (simon@simontuffs.com). All rights reserved. > >Redistribution and use in source and binary forms, with or without >modification, are permitted provided that the following conditions are met: > >Redistributions of source code must retain the above copyright notice, this >list of conditions and the following disclaimer. > >Redistributions in binary form must reproduce the above copyright notice, >this list of conditions and the following disclaimer in the documentation >and/or other materials provided with the distribution. > >Neither the name of P. Simon Tuffs, nor the names of any contributors, >nor the name One-JAR may be used to endorse or promote products derived >from this software without specific prior written permission. > >THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >POSSIBILITY OF SUCH DAMAGE. ================================================ FILE: build.sbt ================================================ name := "sbt-onejar" crossSbtVersions := Seq("0.13.17", "1.1.6") ScriptedPlugin.scriptedSettings scriptedLaunchOpts += ("-Dplugin.version=" + version.value) organization := "org.scala-sbt.plugins" version := "0.9-SNAPSHOT" sbtPlugin := true scalacOptions in Compile ++= Seq("-deprecation") publishTo := Some(Resolver.url("sbt-plugin-releases", new URL("http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)) publishMavenStyle := false ================================================ FILE: notes/0.1.markdown ================================================ * First release of sbt-onejar, for SBT 0.7.7 ================================================ FILE: notes/0.2.markdown ================================================ * Exclude unneeded contents from JAR ================================================ FILE: notes/0.3.markdown ================================================ * Move to SBT 0.10 ================================================ FILE: notes/0.4.markdown ================================================ * Move to SBT 0.11 ================================================ FILE: notes/0.5.markdown ================================================ * Automatically configure the attribute `One-Jar-Main-Class` in the Manifest. ================================================ FILE: notes/0.6.markdown ================================================ * Cross build against SBT 0.11.0 and SBT 0.11.1 ================================================ FILE: notes/about.markdown ================================================ [sbt-onejar][1] is a plug-in for Simple Build Tool that packages your application and its dependencies in a single, executable JAR file using [One-JAR™](http://one-jar.sourceforge.net) The executable JAR contains your third party libraries as nested JARs, much like a WAR file. Alternatives ways to package your application: * As an über-JAR with [sbt-assembly][2] * Obfuscated and trimmed of fat with [xsbt-proguard-plugin][3] * With a graphical installer via [sbt-izpack][4] [1]: https://github.com/retronym/sbt-onejar [2]: https://github.com/eed3si9n/sbt-assembly [3]: https://github.com/siasia/xsbt-proguard-plugin [4]: http://software.clapper.org/sbt-izpack/ ================================================ FILE: project/build.properties ================================================ sbt.version=0.13.17 ================================================ FILE: project/plugins.sbt ================================================ libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value ================================================ FILE: src/main/resources/one-jar-license.txt ================================================ /* * One-JAR (http://one-jar.sourceforge.net). Copyright (c) 2004, * P. Simon Tuffs (simon@simontuffs.com). All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of P. Simon Tuffs, nor the names of any contributors, * nor the name One-JAR may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ ================================================ FILE: src/main/scala/com/github/retronym/SbtOneJar.scala ================================================ package com.github.retronym import sbt._ import Keys._ import java.util.jar.Attributes.Name._ import sbt.Defaults._ import sbt.Package.ManifestAttributes // TODO Either fail if exportJars == false, or access the other project artifacts via BuildStructure object SbtOneJar extends AutoPlugin { object autoImport { val oneJar = TaskKey[File]("one-jar", "Create a single executable JAR using One-JAR™") val oneJarRedist = TaskKey[Set[File]]("one-jar-redist", "The redistributable One-JAR™ launcher, unzipped.") @deprecated("will be removed. add `enablePlugins(SbtOneJar) in build.sbt`", "0.9") def oneJarSettings: Seq[Def.Setting[_]] = SbtOneJar.projectSettings } import autoImport._ override def requires = plugins.JvmPlugin override val projectSettings: Seq[Def.Setting[_]] = inTask(oneJar)(Seq( artifactPath := artifactPathSetting(artifact).value )) ++ Seq( publishArtifact in oneJar := publishMavenStyle.value, artifact in oneJar := moduleName(Artifact(_, "one-jar")).value, packageOptions in oneJar := Seq(ManifestAttributes((MAIN_CLASS, "com.simontuffs.onejar.Boot"))), mainClass in oneJar := (mainClass in run in Compile).value, packageOptions in oneJar ++= (mainClass in oneJar).map { case Some(mainClass) => Seq(ManifestAttributes(("One-Jar-Main-Class", mainClass))) case _ => Seq() }.value, baseDirectory in oneJarRedist := (target.value / "one-jar-redist"), oneJarRedist := { val base = (baseDirectory in oneJarRedist).value val oneJarResourceName = "one-jar-boot-0.97.jar" val s = getClass.getClassLoader.getResourceAsStream(oneJarResourceName) if (s == null) sys.error("could not load: " + oneJarResourceName) def include(path: String) = path match { case "META-INF/MANIFEST.MF" => false case x => !x.startsWith("src/") } IO.unzipStream(s, base, include _) }, mappings in oneJar := { val artifact = (packageBin in Compile).value val classpath = (dependencyClasspath in Runtime).value val oneJarRedistBase = (baseDirectory in oneJarRedist).value val thisArtifactMapping = (artifact, (file("main") / artifact.name).getPath) val deps: Seq[(File, String)] = { val allDeps = Attributed.data(classpath).map(f => (f, (file("lib") / f.name).getPath)) allDeps.filterNot(_._1 == artifact) } val redist = oneJarRedist.value.toSeq pair Path.relativeTo(oneJarRedistBase) Seq(thisArtifactMapping) ++ deps ++ redist }, oneJar := { val output = (artifactPath in oneJar).value val packageConf = new Package.Configuration((mappings in oneJar).value, output, (packageOptions in oneJar).value) Package(packageConf, Compat.cacheStoreFactory(streams.value.cacheDirectory), streams.value.log) output } ) } ================================================ FILE: src/main/scala-sbt-0.13/com/github/retronym/Compat.scala ================================================ package com.github.retronym import java.io.File private[retronym] object Compat { def cacheStoreFactory(base: File) = base } ================================================ FILE: src/main/scala-sbt-1.0/com/github/retronym/Compat.scala ================================================ package com.github.retronym import java.io.File private[retronym] object Compat { def cacheStoreFactory(base: File) = sbt.util.CacheStoreFactory(base) } ================================================ FILE: src/sbt-test/one-jar/basic/build.sbt ================================================ enablePlugins(SbtOneJar) libraryDependencies += "commons-lang" % "commons-lang" % "2.6" ================================================ FILE: src/sbt-test/one-jar/basic/project/plugins.sbt ================================================ addSbtPlugin("org.scala-sbt.plugins" %% "sbt-onejar" % System.getProperty("plugin.version")) ================================================ FILE: src/sbt-test/one-jar/basic/src/main/scala/basic/basic.scala ================================================ package basic object Basic { def main(args: Array[String]) { import org.apache.commons.lang.ObjectUtils println("hello world") } } ================================================ FILE: src/sbt-test/one-jar/basic/test ================================================ > show oneJar::mainClass > show oneJar > show oneJarRedist ================================================ FILE: src/sbt-test/one-jar/multi/alpha/src/main/scala/alpha/alpha.scala ================================================ package alpha object Alpha ================================================ FILE: src/sbt-test/one-jar/multi/beta/src/main/scala/beta/beta.scala ================================================ package beta object Beta { def main(args: Array[String]) { println(alpha.Alpha) } } ================================================ FILE: src/sbt-test/one-jar/multi/build.sbt ================================================ def standardSettings = Seq( exportJars := true ) lazy val alpha = Project("alpha", file("alpha")) .settings(standardSettings) lazy val beta = Project("beta", file("beta")) .dependsOn(alpha) .enablePlugins(SbtOneJar) .settings( standardSettings ) ================================================ FILE: src/sbt-test/one-jar/multi/project/plugins.sbt ================================================ addSbtPlugin("org.scala-sbt.plugins" %% "sbt-onejar" % System.getProperty("plugin.version")) ================================================ FILE: src/sbt-test/one-jar/multi/test ================================================ > show oneJar