这次弄一下maven 多模块项目,用vscode新建一下,便于管理项目
首先 创建一个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>-->
<!-- <!–这里要替换成jar包main方法所在类 –>-->
<!-- <mainClass>GetName</mainClass>-->
<!-- </manifest>-->
<!-- <manifestEntries>-->
<!-- <!–上面指定类的路径–>-->
<!-- <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新建一下,便于管理项目的更多相关文章
- vue初始化项目,构建vuex的后台管理项目架子
构架vuex的后台管理项目源码:https://github.com/saucxs/structure-admin-web 一.node安装 可以参考这篇文章http://www.mwcxs.top/ ...
- iOS 本地项目上传github,github管理项目配置
一.注册github账号 首先需要注册一个github账号,注册地址:https://github.com 接着会来到这 然后会收到一封github发的邮件,进入邮箱验证 二.创建个人的githu ...
- [置顶] Maven多模块项目 eclipse热部署 Maven项目实现 tomcat热部署 二
最近看到有好多童鞋比较热衷热部署,特别是多模块的项目,其实这热部署如果多模块比较大资源,容易内存溢出或者电脑卡住,并不建议这么做. 不过了解下也没有关系,这里我就在说说热部署的另外一种方法,因为我之前 ...
- Maven多模块的开发项目搭建
系统越复杂,所有的业务逻辑都放在一个项目里,各个包之间的业务逻辑相互调用,这样添加了开发成本,同时对之后的系统维护,错误排查带来一定的麻烦. 通过Maven的多模块开发,把一个系统拆分成多个模块,通过 ...
- vue,vuex的后台管理项目架子structure-admin,后端服务nodejs
之前写过一篇vue初始化项目,构建vuex的后台管理项目架子,这个structure-admin-web所拥有的功能 接下来,针对structure-admin-web的不足,进行了补充,开发了具有登 ...
- maven多模块项目,多web合并项目使用心得
Fixflow,做中国最好的开源流程引擎!项目地址https://github.com/fixteam/fixflow 此文章适合maven初学者或想接触maven的用户,讲的只是皮毛,高手请自觉略过 ...
- Maven多模块,Dubbo分布式服务框架,SpringMVC,前后端分离项目,基础搭建,搭建过程出现的问题
现互联网公司后端架构常用到Spring+SpringMVC+MyBatis,通过Maven来构建.通过学习,我已经掌握了基本的搭建过程,写下基础文章为而后的深入学习奠定基础. 首先说一下这篇文章的主要 ...
- maven创建子项目(适用于多模块管理项目)
在eclipse或者myeclipse下构建maven项目,该项目由多个子模块组成. 1.创建一个父项目 NEW -->project-->maven-->maven Project ...
- IntelliJ Idea14 创建Maven多模块项目
Maven多模块项目的参考资料 Sonatype上的教程 http://books.sonatype.com/mvnex-book/reference/multimodule.html 在这个教程里, ...
- Maven入门,Maven项目的创建,nexus 2.x搭建私服以及Maven多模块项目创建
maven的了解做一个总结,以便日后查阅, 若有不足之处,还望指出,学无止境 当然也能起到入门效果. 一,搭建maven私服 1.工具 a. Nexus 2.5.1-01 b. Maven 3.3.9 ...
随机推荐
- 巧用 awk 批量杀进程
今天遇到线上的一个问题: 我需要批量杀死某台机器的 PHP 进程,该怎么办? 注意,不是 php-fpm,是常驻任务. 如果是一个进程,那就好办了,ps -ef | grep php,找到 PID 然 ...
- EasyExcel · 写excel
原文地址 通用数据生成 后面不会重复写 private List<DemoData> data() { List<DemoData> list = ListUtils.newA ...
- C++(继承)
继承 struct Person { int age; int sex; }; struct Teacher { int age; int sex; int level; int classId; } ...
- 记一次因为C#官方扩展导致自动补全出错的情况 (C# & Godot)
现象 最近使用Vscode结合Godot使用时突然发现自动补全出问题了,发现一部分自动补全能弹出补全项目,但是确认后不起作用,还会吞掉弹出自动补全后输入的字符.大概是下图这样的感觉(截图时已修好,图为 ...
- 【动画进阶】神奇的 3D 磨砂玻璃透视效果
最近,群友分享了一个很有意思的效果: 原效果的网址:frosted-glass.该效果的几个核心点: 毛玻璃磨砂效果 卡片的 3D 旋转跟随效果 整体透明度和磨砂感.以及卡片的 3D 形态会随着用户移 ...
- WPF使用TextBlock实现查找结果高亮显示
在应用开发过程中,经常遇到这样的需求:通过关键字查找数据,把带有关键字的数据显示出来,同时在结果中高亮显示关键字.在web开发中,只需在关键字上加一层标签,然后设置标签样式就可以轻松实现. 在WPF中 ...
- 智能AI 的应用场景
小凡智能AI是一款基于人工智能技术开发的助软件,能够帮助用户解决各种各样的问题,提高工作效率和生活质量.它的应用范围广泛,涵盖了工作.学习.健康等多个方面,为用户提供了全方位的服务支持. 在工作方面, ...
- 完全可复制、经过验证的 Go 工具链
原文在这里. 由 Russ Cox 发布于 2023年8月28日 开源软件的一个关键优势是任何人都可以阅读源代码并检查其功能.然而,大多数软件,甚至是开源软件,都以编译后的二进制形式下载,这种形式更难 ...
- 【项目源码】JavaWeb网上购书系统
JavaWeb网上购书系统 介绍 采用JSP.Servlet.MySQL.Tomcat8.0开发的网上购书系统. 软件架构 网上书城主要功能如下: (1) 前台(客户购买)部分: ① 用户管理:注册会 ...
- VB快速上手文档教程
前言 本来我想可能不会接触到这个语言, 不过在用excel时需要用到VBA. 这就不得不专门去学习一番. 入了个门, 专门写个文档留着. 万一以后用得到呢- 论VB, 我还是初学者. 如有弄错了的地方 ...