Maven多模块项目新建技巧-解决公共项目install之后可以在单独模块中直接编译
2024-08-25 05:43:31
说明:如果按照这种方式http://www.cnblogs.com/EasonJim/p/8303878.html,且按照常规的install方式在子项目中编译项目,那么需要先install一下parent项目,最后才能编译子项目。这种方式其实不太好,每次都intall一大堆项目,所以为了解决这种重的方式,可以只install公共模块,然后使其单独能编译子项目。
解决方式:
1、在常规新建的多模块项目(http://www.cnblogs.com/EasonJim/p/6863987.html)时,把公共模块的pom的parent节点去除即可。比如样例工程bus-core-api下的pom如下:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jsoft.test</groupId>
<artifactId>testproject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.jsoft.test</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>
<name>bus-core-api</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
去除了parent节点后是这样的:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jsoft.test</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>
<name>bus-core-api</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
那么这样操作之后,直接install了bus-core-api之后就可以单独编译app-desktop-ui等项目。
注意:子模块去除了parent节点之后,随着而来的特性也会丢失,比如在父项目定义的配置项,那么也不能使用,比如父项目增加的包,那么在子项目也不能继承使用,只能单独自己引入。
测试工程:https://github.com/easonjim/5_java_example/tree/master/maventest/test10/testproject
最新文章
- 使用用户自定义类型 CLR UDT
- 用shebang编写一个ssh自动登陆脚本
- encodeURI来解决URL传递时的中文问题
- JAVA Day6
- 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)
- 浅谈压缩感知(二十八):压缩感知重构算法之广义正交匹配追踪(gOMP)
- Day5_作业
- maven项目搭建
- A few things to remember while coding in Python.
- jquery插件--多行文本缩略
- 【转】shell学习笔记(七)——流程控制之while
- linux 3.10 串口注册
- CF877F
- Flume+Kafka+Storm+Hbase+HDSF+Poi整合
- 精心收集的 95 个超实用的 JavaScript 代码片段( ES6+ 编写)
- TODO java疑问
- CAP:Alantany 谈 CAP
- 瀑布 敏捷 精益 devops
- RocketMQ 消息发送
- talib 中文文档(十五):Math Operator Functions 数学方法