简体   繁体   English

如何在Maven多模块项目中将jar从一个项目打包到另一个项目

[英]How to package jar from one project to another in maven multimodule project

I need a best-practice solution for the following problem. 我需要以下问题的最佳实践解决方案。 I have a maven multi-module project with 3 subprojects: 我有一个包含3个子项目的Maven多模块项目:

  • client-module (simple java app which packaged as .jar) 客户端模块(打包为.jar的简单Java应用)
  • module-1-that-uses-client 模块-1-该用途的客户端
  • module-2-that-uses-client 模块-2-该用途的客户端

module-*-that-uses-client is a bunch of static xml config files with a client-module.jar which is packaged as a .zip file. module-*-that-uses-client是一堆带有client-module.jar的静态xml配置文件,该文件打包为.zip文件。 So, the packaged structure of a module-*-that-uses-client would look like: 因此,使用客户端的模块的打包结构如下所示:

  • client-module.jar 客户module.jar
  • config1.xml config1.xml
  • config2.xml config2.xml
  • config3.xml config3.xml

I wonder how I can implement following build strategies. 我不知道如何实现以下构建策略。 If I build client-module, then: 如果我构建客户端模块,则:

  1. build client-module 建立客户端模块
  2. copy client-module.jar to all module-*-that-uses-client 将client-module.jar复制到所有使用客户端的模块
  3. build all module-*-that-uses-client modules. 构建所有使用客户端模块的模块。

If I build any of module-*-that-uses-client, then: 如果我构建使用客户端的任何模块-*,则:

  1. build client-module 建立客户端模块
  2. copy client-module.jar to exact module-*-that-uses-client 将client-module.jar复制到使用客户端的确切模块*
  3. build exact module-*-that-uses-client modules. 构建使用客户端模块的确切模块*。

Appreciate any help on this problem. 感谢有关此问题的任何帮助。

One solution would be the usage of --also-make and --also-make-dependents . 一种解决方案是使用--also-make--also-make-dependents

--also-make builds all dependencies of the specified module. --also-make生成指定模块的所有依赖项。 Example: mvn --projects module-1-that-uses-client --also-make clean install builds client-module and module-1-that-uses-client in this order. 示例: mvn --projects module-1-that-uses-client --also-make clean install将按此顺序构建客户端模块和module-1-that-uses-client。

--also-make-dependents builds the specified module and all other modules with a dependency to the specified module. --also-make-dependents生成指定模块以及所有其他与指定模块相关的模块。 Example: mvn --projects client-module --also-make-dependents clean install builds first client-module and then both module-*-that-uses-client. 示例: mvn --projects client-module --also-make-dependents clean install会先构建客户端模块,然后再构建两个模块-*-that-uses-client。

See also the Guide to Working with Multiple Modules . 另请参阅《使用多个模块指南》

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM