[英]SBT Compile for uber jar
What is the best way to make a SBT project work in offline environment?使 SBT 项目在离线环境中工作的最佳方法是什么? There is any ways to compile it outside (in network env), eg uber jar with all its dependencies, and then in the offline env just run it?
有什么方法可以在外部(在网络环境中)编译它,例如 uber jar 及其所有依赖项,然后在离线环境中运行它?
For example in Java Maven, We can compile it with uber jar with all dependencies, and then in the offline env just java -jar MyJar.jar
...例如在 Java Maven 中,我们可以使用包含所有依赖项的 uber jar 编译它,然后在离线 env 中只需
java -jar MyJar.jar
...
Thanks.谢谢。
Best bet for creating an uber/fat jar is the sbt assembly plugin .创建 uber/fat jar 的最佳选择是sbt assembly plugin 。 Include it in your project by putting something like the following in
project/assembly.sbt
通过在
project/assembly.sbt
放置类似以下内容的内容,将其包含在您的项目中
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")
Then just running sbt assembly
should create a jar with all the dependencies in target/scala_$SCALA_VERSION
.然后只运行
sbt assembly
应该创建一个包含target/scala_$SCALA_VERSION
所有依赖项的 jar。 You may need to designate a main class for the jar if you want to run it with java -jar
(as opposed to java -cp $jarfile $mainclass
):如果要使用
java -jar
运行它,则可能需要为 jar 指定一个主类(而不是java -cp $jarfile $mainclass
):
mainClass in assembly := Some("package.mainClass")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.