这次弄一下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 ...
随机推荐
- linux内核vmlinux的编译过程(七)
一. vmlinux目标及其构建规则 定义在顶层Makefile中,如下: # The all: target is the default when no target is given on th ...
- python(django启动报错,之编码问题)UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 0: invalid start byte
- React组件设计之性能优化篇
我们是袋鼠云数栈 UED 团队,致力于打造优秀的一站式数据中台产品.我们始终保持工匠精神,探索前端道路,为社区积累并传播经验价值. 本文作者:空山 前言 由于笔者最近在开发中遇到了一个重复渲染导致子组 ...
- Django创建超级管理员用户
python manage.py createsuperuser 后面就会提示你输入用户名.邮箱以及密码.
- oracle 11g手工建库步骤(初学者)
要建立的数据库ORACLE_SID=test1sys和system的密码为oracle1.建立相应的目录mkdir /u01/app/oracle/oradata/test1mkdir /u01/ap ...
- 9、Spring之代理模式
9.1.环境搭建 9.1.1.创建module 9.1.2.选择maven 9.1.3.设置module名称和路径 9.1.4.module初始状态 9.1.5.配置打包方式和依赖 <?xml ...
- Anaconda平台下从0到1安装TensorFlow环境详细教程(Windows10+Python)
1.安装Anaconda Anaconda下载链接:Free Download | Anaconda 下载完成之后,开始安装,修改安装路径至指定文件夹下,由于安装过程比较简单,此处略过: 2.Tens ...
- Pycharm包推荐|自动检查shell脚本问题的包
如图,这个包自动会检测出哪块代码编写有问题,自动提示,这里可以根据提示进行修改,快速高效!!! 包的名字如图:Shell script formatter 太香了
- php-fpm的配置
pass 对应的php-fpm socket,这样nginx就能将请求转发给php-fpm,这个的实现真的是精彩,为什么,因为php-fpm是负责管理多个php进程的,他的稳定性令人赞叹. index ...
- iOS交叉编译
编译objc程序 ~/toolchain4/pre/bin/arm-apple-darwin9-gcc -arch arm -lobjc -framework CoreFoundation -fram ...