gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:28:42 24 4
gpt4 key购买 nike

有没有办法告诉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 One-JAR™

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(在 custom action模型之后的 "package" sbt action),这是不可能的。
GitHub mentions an assembly task,为 jetty 部署量身定制。您可以根据需要进行调整。
code is pretty generic(来自 this post和用户Rio):
 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, classpath: PathFinder, extraJars: PathFinder, exclude: PathFinder => PathFinder) =
packageTask(Path.lazyPathFinder(assemblyPaths(tempDir, classpath, extraJars, exclude)), assemblyOutputPath, packageOptions)
}

关于scala - 使用简单构建工具制作独立jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2887655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com