通过sbt程序集构建时保留Manifest.mf

问题描述 投票:1回答:1

当我使用sbt assembly构建我的项目时,我得到了java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF。谷歌推荐的解决方案是使用MergeStrategy.discard

这有助于构建项目 - 但它在运行时崩溃,因为Dropwizard(依赖项)依赖于manifest.mf中包含的信息(完整的问题详细信息:https://github.com/dropwizard/dropwizard/issues/455)。

遇到该错误时的建议是合并清单。

我已经尝试了Manifest.MF上的所有MergeStrategies,它们看起来像是在做伎俩(filterDistinctLinesconcatfirstlast),它们都会导致构建失败并使用java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF。唯一编译的是discard,但由于Dropwizard依赖于mf文件,导致程序在运行时崩溃。

任何想法在这做什么?有没有办法合并清单,如https://github.com/dropwizard/dropwizard/issues/455的评论中所述?

scala sbt manifest sbt-assembly manifest.mf
1个回答
0
投票

所以我最终这样做了:

  • 分离Scala和Java项目
  • 按原样构建sbt项目 - 将其复制到java项目/ lib目录
  • 为lib / scala项目添加了一个系统dep,并在构建fatjar时使用add-jar插件将这个jar添加到类路径中: <plugin> <groupId>com.googlecode.addjars-maven-plugin</groupId> <artifactId>addjars-maven-plugin</artifactId> <version>1.0.5</version> <executions> <execution> <goals> <goal>add-jars</goal> </goals> <configuration> <resources> <resource> <directory>${real.base.dir}/lib</directory> </resource> </resources> </configuration> </execution> </executions> </plugin>
  • 构建java项目fatjar并部署它 - 它现在可以访问类路径上的scala jar。

脚本(服务器是我制作的java项目的名称):

sbt clean assembly
cp target/scala*/project*.jar server/lib
cd server
mvn clean install
cd ../
cp server/target/server*.jar target
© www.soinside.com 2019 - 2024. All rights reserved.