当我使用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,它们看起来像是在做伎俩(filterDistinctLines
,concat
,first
,last
),它们都会导致构建失败并使用java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF
。唯一编译的是discard
,但由于Dropwizard依赖于mf文件,导致程序在运行时崩溃。
任何想法在这做什么?有没有办法合并清单,如https://github.com/dropwizard/dropwizard/issues/455的评论中所述?
所以我最终这样做了:
<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项目的名称):
sbt clean assembly
cp target/scala*/project*.jar server/lib
cd server
mvn clean install
cd ../
cp server/target/server*.jar target