首先 创建一个mvn项目, 直接在命令行执行, 原型生成:

mvn archetype:generate

选一个maven quick start的template, 然后删除src和target文件夹

在pom.xml里面version 下面加上<packing>pom</packing>

在此目录中再次执行mvn archetype:generate, 构件artifactId选为child1, 完成后自动在mvnparent目录的Pom中添加了<modules> 节点

再次在mvnparent目录执行mvn archetype:generate 生成child2项目, 会在mvnparent的pom.xml中添加child2的module, 把里面没用的build 节点都删掉

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>mvnparent</artifactId>
<groupId>org.caloch</groupId>
<version>1.0-SNAPSHOT</version>
</parent> <artifactId>child2</artifactId>
<packaging>jar</packaging> <name>child2</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> </project>

mvnchild1引用了child2项目的pom.xml, 里面删除groupid和version两个,它们会继承parent, packaging改为jar

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>mvnparent</artifactId>
<groupId>org.caloch</groupId>
<version>1.0-SNAPSHOT</version>
</parent> <artifactId>mvnchild1</artifactId>
<packaging>jar</packaging> <name>mvnchild1</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.caloch</groupId>
<artifactId>child2</artifactId>
<version>${project.version}</version>
</dependency> </dependencies> </project>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>org.caloch</groupId>
<artifactId>mvnparent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging> <name>mvnparent</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies> <modules> <module>mvnchild1</module>
<module>child2</module>
</modules>
</project>

将项目导入idea中可以调试, 运行为 java -cp "加上另外项目的class文件路径"

 D:\source\repos\mvn_multi_module\mvnparent\mvnchild1> java -cp "D:\source\repos\mvn_multi_module\mvnparent\mvnchild1\target\classes;D:\source\repos\mvn_multi_module\mvnparent\child2\target\classes;" child1.App

mvn compile

mvn package

需要指定main class

指定时 java -jar xx.jar可以执行

不指定main class时, 使用java -cp xx.jar {maiclass} 来执行

构建, 在child1的pom里面添加build

  <build>
<plugins> <!--打包普通项目-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!-- 可以指定打包的Main类,也可以不指定-->
<!--指定了某个主类的话,使用: java -jar xxx.jar 参数 来执行-->
<!--不指定主类的话使用:java -cp xxx.jar 类的路径 参数 来执行,注意这里需要手动指定执行类-->
<!-- <archive>-->
<!-- <manifest>-->
<!-- &lt;!&ndash;这里要替换成jar包main方法所在类 &ndash;&gt;-->
<!-- <mainClass>GetName</mainClass>-->
<!-- </manifest>-->
<!-- <manifestEntries>-->
<!-- &lt;!&ndash;上面指定类的路径&ndash;&gt;-->
<!-- <Class-Path>./src/main/java</Class-Path>-->
<!-- </manifestEntries>-->
<!-- </archive>--> <descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- 指定在打包节点执行jar包合并操作 -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin> </plugins>
</build>

运行,注意要运行和dependency一起打包的jar才可以不需要额外添加另外一个包的class path, 否则还是要加class path -cp选项:

cd D:\source\repos\mvn_multi_module\mvnparent\mvnchild1\target

java -cp .\mvnchild1-1.0-SNAPSHOT-jar-with-dependencies.jar child1.App
Hello util in child2

建好的项目文件在:

https://files.cnblogs.com/files/hualiu0/mvnparent.7z?t=1698752418&download=true

这次弄一下maven 多模块项目,用vscode新建一下,便于管理项目的更多相关文章

  1. vue初始化项目,构建vuex的后台管理项目架子

    构架vuex的后台管理项目源码:https://github.com/saucxs/structure-admin-web 一.node安装 可以参考这篇文章http://www.mwcxs.top/ ...

  2. iOS 本地项目上传github,github管理项目配置

    一.注册github账号   首先需要注册一个github账号,注册地址:https://github.com 接着会来到这 然后会收到一封github发的邮件,进入邮箱验证 二.创建个人的githu ...

  3. [置顶] Maven多模块项目 eclipse热部署 Maven项目实现 tomcat热部署 二

    最近看到有好多童鞋比较热衷热部署,特别是多模块的项目,其实这热部署如果多模块比较大资源,容易内存溢出或者电脑卡住,并不建议这么做. 不过了解下也没有关系,这里我就在说说热部署的另外一种方法,因为我之前 ...

  4. Maven多模块的开发项目搭建

    系统越复杂,所有的业务逻辑都放在一个项目里,各个包之间的业务逻辑相互调用,这样添加了开发成本,同时对之后的系统维护,错误排查带来一定的麻烦. 通过Maven的多模块开发,把一个系统拆分成多个模块,通过 ...

  5. vue,vuex的后台管理项目架子structure-admin,后端服务nodejs

    之前写过一篇vue初始化项目,构建vuex的后台管理项目架子,这个structure-admin-web所拥有的功能 接下来,针对structure-admin-web的不足,进行了补充,开发了具有登 ...

  6. maven多模块项目,多web合并项目使用心得

    Fixflow,做中国最好的开源流程引擎!项目地址https://github.com/fixteam/fixflow 此文章适合maven初学者或想接触maven的用户,讲的只是皮毛,高手请自觉略过 ...

  7. Maven多模块,Dubbo分布式服务框架,SpringMVC,前后端分离项目,基础搭建,搭建过程出现的问题

    现互联网公司后端架构常用到Spring+SpringMVC+MyBatis,通过Maven来构建.通过学习,我已经掌握了基本的搭建过程,写下基础文章为而后的深入学习奠定基础. 首先说一下这篇文章的主要 ...

  8. maven创建子项目(适用于多模块管理项目)

    在eclipse或者myeclipse下构建maven项目,该项目由多个子模块组成. 1.创建一个父项目 NEW -->project-->maven-->maven Project ...

  9. IntelliJ Idea14 创建Maven多模块项目

    Maven多模块项目的参考资料 Sonatype上的教程 http://books.sonatype.com/mvnex-book/reference/multimodule.html 在这个教程里, ...

  10. Maven入门,Maven项目的创建,nexus 2.x搭建私服以及Maven多模块项目创建

    maven的了解做一个总结,以便日后查阅, 若有不足之处,还望指出,学无止境 当然也能起到入门效果. 一,搭建maven私服 1.工具 a. Nexus 2.5.1-01 b. Maven 3.3.9 ...

随机推荐

  1. Prometheus-4:服务自动发现Service Discovery

    自动发现 Prometheus的服务发现的几种类型: 基于文件的服务发现: 基于DNS的服务发现: 基于API的服务发现:Kubernetes.Consul.Azure...... Prometheu ...

  2. clickhouse 与 zookeeper

    目录 clickhouse 设置中的 zookeeper 配置 参数说明 配置示例 [预发生产] ClickHouse Keeper 四字母命令 clickhouse 设置中的 zookeeper 配 ...

  3. C#程序的启动显示方案(无窗口进程发送消息) - 开源研究系列文章

    今天继续研究C#的WinForm的实例显示效果. 我们上次介绍了Winform窗体的唯一实例运行代码(见博文:基于C#的应用程序单例唯一运行的完美解决方案 - 开源研究系列文章 ).这就有一个问题,程 ...

  4. CTFshow misc1-10

    小提示:需要从图片上提取flag文字,可以通过截图翻译或者微信发送图片,这两个的ai图像识别挺好用的. misc1: 解压打开就能看见flag,提取出来就行 misc2: 记事本打开,看见 ng字符, ...

  5. 准备HarmonyOS开发环境

    引言 在开始 HarmonyOS 开发之前,需要准备好开发环境.本章将详细指导你如何安装 HarmonyOS SDK.配置开发环境.创建 HarmonyOS 项目. 目录 安装 HarmonyOS S ...

  6. CodeForces 1367F2 Flying Sort (Hard Version)

    题意 给一个长度为\(n\)的数组,你可以有两种操作 将某一个数放置在数组开头 将某一个数放置在数组结尾 问最小操作多少次可以得到一个非递减数列 (比\(F1\)难在\(n\)变大,且数组中元素可以有 ...

  7. 用OLED屏幕播放视频(3): 使用cuda编程加速视频处理

    下面的系列文章记录了如何使用一块linux开发扳和一块OLED屏幕实现视频的播放: 项目介绍 为OLED屏幕开发I2C驱动 使用cuda编程加速视频处理 这是此系列文章的第3篇, 主要总结和记录了如何 ...

  8. Web攻防--Java_SQL注入--XXE注入-- SSTI模板注入--SPEL表达式注入

    预编译 编译器在编译sql语句时,会依次进行词法分析.语法分析.语义分析等操作, 预编译技术会让数据库跳过编译阶段,也就无法就进行词法分析,关键字不会被拆开,注入语句也就不会被识别为SQL的关键字,从 ...

  9. 如何把网页打包成苹果原生APP并上架TF(TestFlight)

    打包网页APP并上架到TestFlight流程 需要准备的材料: 1. GDB苹果网页打包软件1.6.0或者以上版本: https://www.cnblogs.com/reachteam/p/1229 ...

  10. SQL查询中的小技巧:SELECT 1 和 LIMIT 1 替代 count(*)

    前言 在写SQL查询时,常规做法是使用SELECT count(*)来统计符合条件的记录数. 然而,在某些情况下,我们只关心是否存在符合条件的记录,而不需要知道具体的记录数. 为了优化性能,可以改用使 ...