我正在尝试使用 Maven 将 Web 应用程序打包为可运行的 JAR 文件。 jar-with-dependencies 程序集负责包含所有依赖项,但我仍然需要包含 src/main/webapp。
我设法使用自定义程序集将目录添加到我的 JAR 中:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>webapp</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/webapp</directory>
<outputDirectory>/webapp</outputDirectory>
</fileSet>
</fileSets>
</assembly>
它确实有效,甚至可以将此程序集与 jar-with-dependencies 一起使用。但是,最终的 JAR 包含 webapp 目录和所有依赖项,但不包含我项目的类文件。我的程序集显然正在删除它们。
我可以在程序集中保留我自己项目的类文件吗?还是有另一种方法可以将目录添加到 JAR 中?
最佳答案
My assembly is apparently removing them
我猜恰恰相反,不添加它们。
您的类文件位于 target/classes 中,它们需要位于 target/webapp/WEB-INF/classes 中。我猜你需要这样的另一个规则:
<fileSet>
<directory>target/classes</directory>
<outputDirectory>/webapp/WEB-INF/classes</outputDirectory>
</fileSet>
关于java - 如何使用 Maven 将目录添加到 JAR 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9427628/