如何在 Maven JAR 中包含 Java 源代码
问题
你使用 Maven 作为构建系统,但你需要将 Java 源代码包含在 mvn package 生成的 JAR 文件中。
解决方案
将以下 XML 代码包含到你的 pom.xml 中(在 project 元素内):
pom_include_sources.xml
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</build>如果你的 pom.xml 中已有元素,你需要在之后添加上面之间的所有内容。
相关问题:
- 如果你需要生成带源代码的单独 JAR,请参见 Maven Sources 插件:http://maven.apache.org/plugins/maven-source-plugin/
- 也请查看此相关 StackOverflow 讨论
Check out similar posts by category:
Java
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow