maven pom.xml配置解析
来源:互联网 发布:psp软件 编辑:程序博客网 时间:2024/06/09 13:41
(一)简单pom.xml配置:
<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>com.alib</groupId> <artifactId>ntytest</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>ntytest</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>${spring.data.jpa.version}</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <jdk.version>1.6</jdk.version> <junit.version>4.12</junit.version> <servlet.version>3.0.1</servlet.version> </properties> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin><!-- 设置了profile必须在build中定义resources节点,表明那个目录下的资源需要被profile中的值代替 --> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>spring-config.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <excludes> <exclude>spring-config.xml</exclude> </excludes> <filtering>false</filtering> </resource> </resources> </build> <profiles> <profile> <id>dev</id> <properties> <properties.dir>/app/test/configs</properties.dir> </properties> </profile> <profile> <id>st</id> <properties> <properties.dir>/app/test2/configs</properties.dir> </properties> </profile> </profiles>
上述代码是maven pom.xml文件的基本配置:
maven坐标:一个项目的确定是由groupId、artifactId和version来决定。
《packaging》表示打包的类型为war。
《dependency》引入项目依赖的jar包
《exclusion》引入的jar包又引入了其他的jar,可选择行排除
《properties》该配置可以用${}形式引入参数
《plugin Managment》管理maven的插件,这个与《pligins》之间的区别在于模块化管理,使用这个标签可以让子模块选择父项目的插件
《profiles》配置不同环境的参数
(二)模块化管理
对于一个较为复杂的项目,一般都会分开不同的模块让不同的开发人员进行独立开发,maven在这方面就做的很好。
(1)首先建立一个parent项目,只保留pom.xml
<?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> <groupId>com.aliby</groupId> <artifactId>nty</artifactId> <version>2.0.0-SNAPSHOT</version> <!-- 用于工程聚合,一般情况下不要修改 --> <packaging>pom</packaging> <name>nty</name> <url>http://maven.apache.org</url> <modules> <module>nty-manager-api</module> <module>nty-dao</module> <module>nty-common</module> <module>nty-core-service</module> <module>nty-controller</module> <module>nty-web</module> </modules> <properties> <pub-nty.version>2.0.0-SNAPSHOT</pub-nty.version> <!-- 版本,统一控制 --> <jdk.version>1.7</jdk.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties</project>
(2)构建子模块依赖父项目《parent》,各子模块间可相互依赖引用
<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> <groupId>com.mucfc</groupId> <artifactId>nty</artifactId> <version>2.0.0-SNAPSHOT</version> </parent> <groupId>com.mucfc.pub-nty</groupId> <artifactId>nty-manager-api</artifactId> <version>${nty.version}</version> <name>pub-nty-manager-api</name> <dependencies> <dependency> <groupId>com.mucfc.nty</groupId> <artifactId>nty-dao</artifactId> <version>${pub-nty.version}</version> </dependency> <dependency> <groupId>com.mucfc.nty</groupId> <artifactId>nty-api</artifactId> <version>${nty.version}</version> </dependency> </dependencies></project>
0 0
- maven pom.xml配置解析
- Maven pom.xml配置
- maven pom.xml 配置
- maven-pom.xml配置
- maven pom.xml配置
- maven:pom配置解析
- Maven pom.xml 文件解析
- maven的pom.xml解析
- maven 中pom.xml解析
- Maven的pom.xml解析
- Maven中pom.xml解析
- Maven pom.xml 文件解析
- Maven中的pom.xml解析
- maven pom.xml配置说明
- maven pom.xml jetty 配置
- Maven pom.xml 配置详解
- Maven pom.xml 配置详解
- maven pom.xml配置讲解
- 用软件开发技能撑起自己的未来
- 查看linux占用内存/CPU最多的进程
- Python集合set与frozenset的区别
- poj1008 模拟
- PostgreSQL中表名、字段名大小写问题
- maven pom.xml配置解析
- Android网络编程之Http请求服务器数据(GET方式)
- leetcode刷题系列C++-Search in Rotated Sorted Array
- 测试一下
- selenium之二
- JAVA的23中涉及模式详解
- Android中程序与Service交互的方式——交互方式
- LeeCode Invert Binary Tree
- 三分钟了解mongodb