加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 使用简单构建工具制作独立的jar

发布时间:2020-12-16 09:43:53 所属栏目:安全 来源:网络整理
导读:有没有办法告诉sbt将所有需要的库(scala-library.jar)打包到主包中,因此它是独立的? (静态的?) 解决方法 编辑2011: 从那时起, retronym(其中发布了一个 answer in this page back in 2010),这个 sbt-plugin “sbt-onejar”现在在 new address on GitHu
有没有办法告诉sbt将所有需要的库(scala-library.jar)打包到主包中,因此它是独立的? (静态的?)

解决方法

编辑2011:
从那时起, retronym(其中发布了一个 answer in this page back in 2010),这个 sbt-plugin “sbt-onejar”现在在 new address on GitHub,文档更新为SBT 0.12。

Packages your project using 07004

onejar-sbt is a simple-build-tool 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.

原始答案:

直接地说,如果没有延长sbt(“package” sbt action之后的custom action),这是不可能的。

GitHub mentions an assembly task,定制的码头部署。你可以适应你的需要。

code is pretty generic(从this post和用户里约):

project / build / AssemblyProject.scala

 import sbt._

 trait AssemblyProject extends BasicScalaProject
 {
         def assemblyExclude(base: PathFinder) = base / "META-INF" ** "*"
         def assemblyOutputPath = outputPath / assemblyJarName
         def assemblyJarName = artifactID + "-assembly-" + version + ".jar"
         def assemblyTemporaryPath = outputPath / "assembly-libs"
         def assemblyClasspath = runClasspath
         def assemblyExtraJars = mainDependencies.scalaJars

         def assemblyPaths(tempDir: Path,classpath: PathFinder,extraJars: PathFinder,exclude: PathFinder => PathFinder) =
         {
                 val (libs,directories) = classpath.get.toList.partition(ClasspathUtilities.isArchive)
                 for(jar <- extraJars.get ++ libs) FileUtilities.unzip(jar,tempDir,log).left.foreach(error)
                 val base = (Path.lazyPathFinder(tempDir :: directories) ##)
                 (descendents(base,"*") --- exclude(base)).get
         }

         lazy val assembly = assemblyTask(assemblyTemporaryPath,assemblyClasspath,assemblyExtraJars,assemblyExclude) dependsOn(compile)
         def assemblyTask(tempDir: Path,exclude: PathFinder => PathFinder) =
                 packageTask(Path.lazyPathFinder(assemblyPaths(tempDir,classpath,extraJars,exclude)),assemblyOutputPath,packageOptions)
 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读