pom文件中的节点以及含义
maven中添加依赖
比如添加fastjson依赖
<dependencies>
<!-- 添加FastJSON依赖: jar文件 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
</dependencies>
如果想打包带有依赖的项目:
需要在pom文件中添加:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
使用的maven命令是:mvn assembly:assembly。
tarage目录下就会多一个jar:
运行jar文件:
java -cp jar文件路径 包名.包名…类名
注意: 类中含有main函数.
Maven继承:
注意:
第2步: 父项目打包方式及添加依赖
a.父项目打包方式必须为pom格式.[配置<packaging>pom</packaging>]
b.<dependencies>和<dependencyManagement>方式
<dependencies>声明的依赖,默认被子项目全部继承.
<dependencyManagement>声明的依赖,子项目只能继承依赖的版本号。
示例:
fastjson依赖:
手动创建父项目:parent和子项目child
父项目中的pom文件:
<!-- 版本:4.0.0 -->
<modelVersion>4.0.0</modelVersion>