我是 Maven 的新手,我想我已经开始了解它是如何工作的了。但我无法理解 Maven 程序集插件。我想要实现的是:
当所有项目及其各自的依赖项都已打包后,我希望将它们全部放在目标目录中。我不希望它们被打包成一个超级jar,因为系统是基于模块的。
让我解释一下,我有一个主项目,服务器,在maven项目“common”中,我有两个模块,“core”和“android”。在公共文件夹中,还有一个我要复制的conf文件夹。我想要这样的结构:
- 目标/common.jar
- 目标/conf/(配置文件)
- 目标/模块/core.jar
- 目标/模块/android.jar
我的项目结构是这样的:
- pom.xml(父项目)
- 通用/(maven 模块)
- 核心/(maven 模块)
- android/(maven 模块)
感谢您提供任何帮助,或以正确的方式指出。 :)
EDIT这是 100% 运行的 ant 构建文件,也许我应该保留它?
<target name="init">
<mkdir dir="dist" />
<mkdir dir="dist/conf/" />
<mkdir dir="dist/modules/" />
<mkdir dir="dist/libs/" />
<copy includeemptydirs="false" todir="dist/conf">
<fileset dir="common/conf" />
</copy>
</target>
<target name="copy-server">
<copy todir="dist">
<fileset file="common/target/server*.jar" />
</copy>
</target>
<target name="copy-modules">
<copy todir="dist/modules/">
<fileset file="core/target/*.jar" />
<fileset file="android/target/*.jar" />
</copy>
</target>
<target name="copy-libs">
<copy todir="dist/libs">
<fileset dir="common/target/libs" />
<fileset dir="core/target/libs" />
<fileset dir="android/target/libs" />
</copy>
<delete>
<fileset file="dist/libs/server*.jar" />
</delete>
</target>
<target name="clean">
<delete dir="dist" />
</target>
<target name="full-build" depends="clean, init, copy-server, copy-libs, copy-modules, increment">
<echo message="Copying the fully built Maven project" />
</target>
<target name="increment">
<propertyfile file="common/conf/version.properties">
<entry key="build.number" type="int" operation="+" default="0" />
</propertyfile>
<property file="common/conf/version.properties" />
<echo message="Build number is ${build.number}"/>
</target>
首先,程序集插件的作用:它使制作包含 Maven 项目的工件、依赖项和其他相关文件的 tar 或 zip 存档变得非常容易。
听起来你需要做的就是设置程序集插件 http://maven.apache.org/plugins/maven-assembly-plugin/usage.html使用自定义描述符来提取您感兴趣的 jar 和配置文件。如果您有一个代表“可分发”事物的模块 - 即使该模块依赖于其他模块 - 那么您可能只需添加一个汇编描述符 http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html其中包括一些files http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_file, fileSets http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_fileSet,和/或依赖集 http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet.
如果您的项目中有多个模块需要包含,并且没有任何模块依赖于所有这些模块,那么您需要查看模块集 http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_moduleSet。我自己从来没有使用过这些,但它们正是为了解决这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)