[英]sbt-assembly: how to link dependencies jar with main jar?
I am coding in scala and using SBT with sbt-assembly plugin. 我在scala中编码并使用SBT和sbt-assembly插件。 My project has a lot of external libraries, and therefore sbt-assembly takes a long time to pack the JAR file.
我的项目有很多外部库,因此sbt-assembly需要很长时间来打包JAR文件。 I would like to have a separate jar files for my code and for the dependencies.
我想为我的代码和依赖项创建一个单独的jar文件。 Therefore, I could simply recompile and repack only my code.
因此,我可以简单地重新编译并重新打包我的代码。 How to do this?
这个怎么做?
Progress so far: 迄今取得的进展:
The following commands in the build.sbt
prevents sbt-assembly from packing the libraries: build.sbt
的以下命令阻止sbt-assembly打包库:
assembleArtifact in packageScala := false
assembleArtifact in packageDependency := false
Then separate jars can be built by passing following commands: assembly
, assembly-package-scala
and assembly-package-dependency
. 然后可以通过传递以下命令来构建单独的jar:
assembly
, assembly-package-scala
和assembly-package-dependency
。 They make three jars: one containing my program, one with scala libraries and one with all the dependencies. 他们制作了三个罐子:一个包含我的程序,一个包含scala库,另一个包含所有依赖项。
However, the jar file is not executable anymore because it does not see the dependencies in the separate jar file. 但是,jar文件不再可执行,因为它没有在单独的jar文件中看到依赖项。 I think I need to add a classpath to assembly-sbt, but I am not sure how to do this.
我想我需要为assembly-sbt添加一个类路径,但我不知道该怎么做。
See Setting Classpath Still Can't Find External Jar . 请参阅设置类路径仍然无法找到外部Jar 。 Oracle says:
甲骨文说:
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
使用此选项时,JAR文件是所有用户类的源,并忽略其他用户类路径设置。
So, you have to say: 所以,你必须说:
java -cp "foo-assembly-0.1-deps.jar:foo-assembly-0.1.jar" Main
where Main
is the name of the main class, and :
is the file separator on your OS ( ;
on Windows) . 其中
Main
是主类的名称,并且:
是OS上的文件分隔符( ;
在Windows上)。
Currently there seems to be a bug in assembly-package-scala
and it comes out empty, but it shouldn't matter because assembly-package-dependency
contains Scala library too. 目前在
assembly-package-scala
似乎存在一个错误并且它是空的,但它应该没关系,因为assembly-package-dependency
包含Scala库。
Use sbt-pack plugin at https://github.com/xerial/sbt-pack . 在https://github.com/xerial/sbt-pack上使用sbt-pack插件。 So far I've found it the cleanest way to pack the project and dependencies.
到目前为止,我发现它是打包项目和依赖项的最简洁方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.