这次弄一下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 ...
随机推荐
- 【ssh】SSH连接远程主机的两种方式
一.基于用户名与密码连接 指令 ssh username@server_ip 随后要求输入密码 加密流程 1️⃣ 在SSH连接建立过程中,客户端和服务器使用Diffie-Hellman密钥交换协议协商 ...
- 开发自己的Prometheus Exporter、实现自定义指标
Prometheus Exporter基础知识 Prometheus Exporter的概念.工作原理 Prometheus Exporter是一个用来收集和暴露指标数据的工具,通过与Prometh ...
- ls 和 du显示文件大小不一样
查看当前文件系统的磁盘使用 df -k / Filesystem 1K-blocks Used Available Use% Mounted on /dev/nvme0n1p2 97844508 37 ...
- 理解TCP3次握手
以AB通话为例 A的视角 A给B打电话,进入SYN_SENT B接起电话,A确认后,进入ESTABLISHED B的视角 看到A打过来的电话,接起电话,进入SYN_RCVD 确认对方后,进入ESTAB ...
- IRF技术介绍及配置介绍
IRF技术介绍及配置介绍 IRF(Intelligent Resilient Framework,智能弹性架构)是 H3C 自主研发的软件虚拟化技术. 它的核心思想是将多台设备通过 IRF 物理端口连 ...
- 2021-7-11 Vue的计算属性和侦听器
计算属性是为了让页面显示更加简洁,基于data数据进行处理的方法,以下为实例 <!DOCTYPE html> <html> <head> <title> ...
- 【工具推荐】github打不开or加载慢?不用配置hosts,教你一键加速!
不说废话 下载watt toolkit(原名steam++) 官方地址: Watt Toolkit - 瓦特工具箱(Steam++官网) (steampp.net) 安装完后选中,点击一键加速即可. ...
- Nginx 文件名逻辑漏洞(CVE-2013-4547)(Vulhub)
Nginx 文件名逻辑漏洞(CVE-2013-4547)(Vulhub) 漏洞简介 在Nginx 0.8.41 ~ 1.4.3 / 1.5.0 ~ 1.5.7版本中存在错误解析用户请求的url信息,从 ...
- SpringBoot3.x原生镜像-Native Image实践
前提 之前曾经写过一篇<SpringBoot3.x 原生镜像-Native Image 尝鲜>,当时SpringBoot处于3.0.0-M5版本,功能尚未稳定.这次会基于SpringBoo ...
- BUGKU逆向reverse 1-8题
练习IDA两年半 打开尘封已久的bugku,从题目中练习使用,现在都已经是新版本了 orz 入门逆向 运行baby.exe将解压后的baby.exe拖到IDA里面主函数中找到mov指令 可以看到这里就 ...