sbt / sbt-onejar Goto Github PK
View Code? Open in Web Editor NEWPackages your project using One-JAR™
License: MIT License
Packages your project using One-JAR™
License: MIT License
Hey hey,
Just tried to add one-jar to extradoc that I forked to see if one could create a binary version negating the need for shell scripts and using the one-jar sbt plugin results in:
λ java -jar extradoc_2.8.0-0.1-SNAPSHOT-onejar.jar
error: fatal error: object scala not found.
one error found
You see this error when the scala library cannot be properly loaded. Any ideas? I'm unsure if this is a direct issue with the plugin or one-jar itself. There was some funky stuff going on with one-jar which was why I have ditched it at work in favour of Apache Shade.
Cheers, Tim
...please!
Hiya,
Not sure if this is by design, but I'm assuming that if I'm in SBT and type...
one-jar
one-jar
...the second invocation should do no work. However it always seems to rebuild the artifact.
My SBT foo isn't strong enough to work out whether this is a missing dependency rule or something else.
I've used the sbt-onejar plugin to package my app as single jar. When I invoke it using "java -jar my-jar.jar" I get tons of warnings like these:
JarClassLoader: Warning: JDOMAbout$Author.class in lib/jdom-1.1.jar is hidden by lib/jdom-1.0.jar (with different bytecode)
JarClassLoader: Warning: JDOMAbout$Info.class in lib/jdom-1.1.jar is hidden by lib/jdom-1.0.jar (with different bytecode)
JarClassLoader: Warning: JDOMAbout.class in lib/jdom-1.1.jar is hidden by lib/jdom-1.0.jar (with different bytecode)
JarClassLoader: Warning: org/jdom/adapters/AbstractDOMAdapter.class in lib/jdom-1.1.jar is hidden by lib/jdom-1.0.jar (with different bytecode)
JarClassLoader: Warning: org/jdom/adapters/CrimsonDOMAdapter.class in lib/jdom-1.1.jar is hidden by lib/jdom-1.0.jar (with different bytecode)
Is there some way to turn this noise off?
After adding plugin to build.sbt, sbt loaded sbt-onejar but then complained "one-jar" is not a valid command???
Java HotSpot(TM) Client VM warning: ignoring option MaxPermSize=256m; support wa
s removed in 8.0
[info] Loading project definition from C:\scala\db\project
[info] Updating {file:/C:/scala/db/project/}db-build...
[info] Resolving org.scala-sbt.ivy#ivy;2.3.0-sbt-2cf13e211b2cb31f0d3b317289dca70
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.s
cala-sbt.plugins/sbt-onejar/scala_2.10/sbt_0.13/0.8/jars/sbt-onejar.jar ...
[info] [SUCCESSFUL ] org.scala-sbt.plugins#sbt-onejar;0.8!sbt-onejar.jar (2216m
s)
[info] Done updating.
[info] Set current project to db (in build file:/C:/scala/db/)
> one-jar
[error] Not a valid command: one-jar
[error] Not a valid key: one-jar (similar: on-load, unmanaged-jars, export-jars)
[error] one-jar
[error] ^
I am using one-jar to package my application. I am also using aspectj for some of the functionality. However, it is taking too much time (5min- 15min) just to start the jar file if I provide the javaagent as the aspectjweaver jar file. It is working fine if I run through sbt, with no delay in weaving. Is there anything I can do to make it faster ?
Also, I guess, I have to explicitly provide the javaagent while running the jar file. Is it not able to take it from the build.sbt, or am I missing something ?
Hi,
tried this plugin with SBT 1.0 and Scala 2.12 and I saw it's not supported.
Just wanted to know if the project is still maintained.
I was having troubles with Akka and sbt-assembly so I made some changes to make this plugin working with this configuration.
I don't know if this is a bug report, a feature request or a request for additional documentation.
I would like to be able to use one-jar as a global plugin, i.e. declared not in my project but in "~/.sbt/plugins/".
However, according to the documentation in the README (https://github.com/sbt/sbt-onejar/blob/master/README.md), I need to add settings (https://github.com/retronym/sbt-onejar/blob/master/src/sbt-test/one-jar/basic/build.sbt#L1) to my project's build.sbt.
Now, if a user who doesn't have one-jar installed as a global plugin clones my project and tries to run sbt, he will get the following error:
build.sbt:22: error: object github is not a member of package com
seq(com.github.retronym.SbtOneJar.oneJarSettings: _*)
^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
Ideally, I would like not to be required to add anything to a project's "build.sbt" in order to use one-jar on this project. Would this be possible? Would it be possible to implement the necessary features to make this possible, at least for simple projects with a single main class?
If it is really necessary to add something in "build.sbt", would it be possible to make it in such a way that users without one-jar globally installed would still be able to run SBT without seeing the error above?
Finally, in case I misunderstood the README documentation somehow, could you please add some remarks in the documentation, explaining how to use one-jar as a globally installed plugin, as I described above?
Thanks!
Best regards!
I have 2 main classes in my project. Just specifying any of these:
mainClass := Some("project.App")
mainClass in run := Some("project.App")
mainClass in compile := Some("project.App")
will bring up the "Multiple main classes detected, select one to run" dialog in sbt (0.13.0). Using the oneJar scope works. If working as intended, the documentation should be updated.
One-Jar-Expand
might help here as well, but I think not requiring runtime expansion of the fat jar is nicer.
The purpose of this would be to support libraries that cannot handle nested JARs such as (embedded) Jetty. The problem with e.g. Jetty is that it's not able to find .jsp
files from within nested JARs just always reporting a 404.
I think adding a setting to enable the "splatting" of the main jar directly into the final jar would not be a difficult task but would provide a clean solution for the aforementioned problem.
If, on the other hand, OneJar already supports this, it would be nice to be able to pass the respective setting through to it via sbt-onejar settings.
I tried adding the plugin but every time it was marked as "Unknown Artifact" in Intellij. Hence the one-jar command never worked.
I checked the default resolvers in SBT, and in the below link, the Scala 2.11 or 2.12 folders are not present. Hence the plugin does not work.
Link - https://dl.bintray.com/sbt/sbt-plugin-releases/org.scala-sbt.plugins/sbt-onejar/
Contents -
scala_2.10/
scala_2.9.2/
Could you please add support for at least 2.11. Thanks.
sbt-onejar plugin 0.7 works on sbt 0.11.2 but I want to upgrade sbt to 0.11.3.
It seems that sbt-onejar plugin is ready for sbt 0.11.3 by this commit:
65a61c1
Is the version of sbt-onejar plugin for sbt 0.11.3 already published?
or Are there a plan to release the new version which support sbt 0.11.3?
I have an sbt project with a very basic class. It works perfectly but when I'm trying to run it in Docker using simple docker run imagename
command it throws
Error: Could not find or load main class java -jar scala_test_trash_2.11-1.0-one-jar.jar
Main class:
package com
object Main extends App {
println("Testing hello world.")
}
build.sbt:
import com.github.retronym.SbtOneJar
import com.github.retronym.SbtOneJar.oneJar
import sbt.Keys.mainClass
name := "scala_test_trash"
version := "0.1"
scalaVersion := "2.11.12"
lazy val rootProject = (project in file("."))
.settings(
Seq(exportJars := true),
SbtOneJar.oneJarSettings,
libraryDependencies ++= Seq(
"com.google.cloud" % "google-cloud-pubsub" % "0.34.0-beta",
"com.sendgrid" % "sendgrid-java" % "2.2.2"
),
mainClass in oneJar := Some("com.Main")
)
plugins.sbt:
addSbtPlugin("org.scala-sbt.plugins" % "sbt-onejar" % "0.8")
Dockerfile:
FROM gcr.io/google_appengine/openjdk
WORKDIR /test_service
ADD ./target/scala-2.11/scala_test_trash_2.11-0.1-one-jar.jar /test_service
CMD ["java -jar scala_test_trash_2.11-1.0-one-jar.jar"]
I get an unresolved dependency error when I try to use sbt-onejar 0.6 from sbt-0.11.2. Here's my plugins.sbt:
resolvers += "retronym-releases" at "http://retronym.github.com/repo/releases"
addSbtPlugin("com.github.retronym" % "sbt-onejar" % "0.6")
And here's the error message:
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.github.retronym#sbt-onejar;0.6: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.github.retronym:sbt-onejar:0.6 (sbtVersion=0.11.2, scalaVersion=2.9.1)
[warn]
[error] {file:/Users/dlee/prj/operator/node-agent/project/}root/*:update: sbt.ResolveException: unresolved dependency: com.github.retronym#sbt-onejar;0.6: not found
What's weird is that I can see a link to the artifact in the repo (http://retronym.github.com/repo/releases/com/github/retronym/), but get a 404 if I click on it (http://retronym.github.com/repo/releases/com/github/retronym/sbt-onejar_2.9.1_0.11.2/0.6/sbt-onejar-0.6.jar).
If I understand correctly how sbt-onejar operates then one needs to run the package
command first to generate all the "normal" JARs, and only then run the one-jar
command to have those compiled into a big fat JAR with the dependencies. However, if the package
command hasn't been run previously, one-jar
will still happily produce a non-working JAR with just the dependencies in it. I think this serves no value and should be fixed either by automatically running package
or displaying an error message.
Playframework's SBT plugin is able to do so without using exportJars := true option. There should be a way to make SBT plugin to work without exportJars := true as well.
Hi,
While running my one-jar application I get:
JarClassLoader: Warning: Null manifest from input stream associated with: lib/aspectjrt-1.6.11.jar
There is an open bug report with one-jar:
http://sourceforge.net/p/one-jar/bugs/68
Is there a workaround if I want to use sbt-onejar?
Thanks!
Paul
Is it planned to support sbt 0.10.x ?
When running oneJar with the following configuration:
lazy val utils = Project(id="utils", base=file("utils"), settings=utilsSettings)
val utilsSettings = Seq(
name := "Utilities",
version := "1.0.0",
organization := "myorg",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "1.6.1" % "test",
"org.apache.httpcomponents" % "httpclient" % "4.1.2"
),
unmanagedClasspath in Compile := (file("ant/testlib") ** "*.jar").get.classpath,
unmanagedClasspath in Runtime := (file("ant/testlib") ** "*.jar").get.classpath,
mainClass := Some("foo"),
artifactPath in SbtOneJar.oneJar := file("/tmp/foo.jar"),
projectID in SbtOneJar.oneJar := ModuleID("a","b","c"),
exportJars := true
) ++ SbtOneJar.oneJarSettings
I get
[error] References to undefined settings:
[error]
[error] utils/compile:package-bin from utils/*:mappings(for one-jar)
[error]
[error] utils/runtime:dependency-classpath from utils/*:mappings(for one-jar)
[error]
[error] utils/*:module-name from utils/*:artifact(for one-jar)
[error]
[error] utils/*:cache-directory(for one-jar) from utils/*:cache-directory(for one-jar)
[error]
[error] utils/*:target from utils/*:base-directory(for one-jar-redist)
[error]
[error] utils/*:cross-target(for one-jar) from utils/*:artifact-path(for one-jar)
[error]
[error] Use 'last' for the full log.
Currently if your project has multiple main classes, you must select one when running one-jar
, but the resultant jar file always has the same name. It would be nice to either (a) automatically include the main class's name in the jar file name, or generate a one-jar for each main class that exists.
java.lang.IllegalArgumentException: URI is not hierarchical
at java.io.File.<init>(File.java:418)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: java.lang.ExceptionInInitializerError
This runs fine when being executed by sbt run
I need to build a single jar for my module so that it can be used as a javaagent
.
I have a multi-module sbt project and this particular module is the lowest level one.
Can I use OneJar to override how the lowest level module is packaged?
There don't seem to be a setting or an obvious way to set the One-Jar-Expand
attribute you'd normally set by means of a boot-manifest.mf
file in the root directory.
Could this be added to sbt-onejar in one way or another?
Hello,
I have a file in main/resources and I want to include it in the jar. It is not included when running one-jar
. Is there a way to include it ?
IMO having duplicate jars is pretty common for a moderately sized project. with sbt one-jar i get this error. I do not seem to find any help to avoid this.
[error] ...*:one-jar: java.util.zip.ZipException: duplicate entry: lib/slf4j-log4j12-1.6.1.jar
Thanks
Would be great to have support for prepending scripts to jar outputted b this plugin, as is available with the sbt-assembly plugin: https://github.com/sbt/sbt-assembly#prepending-shebang
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.github.retronym#sbt-onejar;0.7: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.github.retronym:sbt-onejar:0.7 (sbtVersion=0.12, scalaVersion=2.9.2)
[warn]
sbt.ResolveException: unresolved dependency: com.github.retronym#sbt-onejar;0.7: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:214)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:121)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:102)
at sbt.IvySbt.liftedTree1$1(Ivy.scala:49)
at sbt.IvySbt.action$1(Ivy.scala:49)
at sbt.IvySbt$$anon$3.call(Ivy.scala:58)
at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:75)
at xsbt.boot.Locks$GlobalLock.withChannelRetries$1(Locks.scala:58)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:79)
at xsbt.boot.Using$.withResource(Using.scala:11)
at xsbt.boot.Using$.apply(Using.scala:10)
at xsbt.boot.Locks$GlobalLock.liftedTree1$1(Locks.scala:51)
at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:51)
at xsbt.boot.Locks$.apply0(Locks.scala:30)
at xsbt.boot.Locks$.apply(Locks.scala:27)
at sbt.IvySbt.withDefaultLogger(Ivy.scala:58)
at sbt.IvySbt.withIvy(Ivy.scala:99)
at sbt.IvySbt.withIvy(Ivy.scala:95)
at sbt.IvySbt$Module.withModule(Ivy.scala:114)
at sbt.IvyActions$.update(IvyActions.scala:121)
at sbt.Classpaths$$anonfun$work$1$1.apply(Defaults.scala:951)
at sbt.Classpaths$$anonfun$work$1$1.apply(Defaults.scala:949)
at sbt.Classpaths$$anonfun$doWork$1$1$$anonfun$54.apply(Defaults.scala:972)
at sbt.Classpaths$$anonfun$doWork$1$1$$anonfun$54.apply(Defaults.scala:970)
at sbt.Tracked$$anonfun$lastOutput$1.apply(Tracked.scala:35)
at sbt.Classpaths$$anonfun$doWork$1$1.apply(Defaults.scala:974)
at sbt.Classpaths$$anonfun$doWork$1$1.apply(Defaults.scala:969)
at sbt.Tracked$$anonfun$inputChanged$1.apply(Tracked.scala:45)
at sbt.Classpaths$.cachedUpdate(Defaults.scala:977)
at sbt.Classpaths$$anonfun$45.apply(Defaults.scala:856)
at sbt.Classpaths$$anonfun$45.apply(Defaults.scala:853)
at sbt.Scoped$$anonfun$hf10$1.apply(Structure.scala:586)
at sbt.Scoped$$anonfun$hf10$1.apply(Structure.scala:586)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49)
at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:41)
at sbt.std.Transform$$anon$5.work(System.scala:71)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:238)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
error sbt.ResolveException: unresolved dependency: com.github.retronym#sbt-onejar;0.7: not found
Is there a way to exclude certain lib jars? For example, I don't want to include the scala-library.jar since I am using this in a java only project. Also, I have a library that is needed for compilation only and not at runtime.
I want configuration folder config/* to be part of classpath but not part of -one.jar, how can I achieve this ? Because I want deployment to be
xyz.one-jar.jar
config/
I don't want config to be compiled in jars.
How does one include native libraries using sbt-onejar?
Given the poor handling of the recent security incident (https://arstechnica.com/information-technology/2021/09/travis-ci-flaw-exposed-secrets-for-thousands-of-open-source-projects/) I'm suspending Travis CI integration indefinitely.
Let's move on to GitHub Actions.
As a novice to Scala, I like your plugin very much. It is explained very clearly in the readme, it is compact and it works.
I want have a choice to decide which main class to entrance rather then package twice only change .sbt settings. Does it possible? Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.