maven(四):一个基本maven项目的pom.xml配置
2017-01-07 09:03
399 查看
继续之前创建的test项目,一个基本项目的pom.xml文件,通常至少有三个部分
第一部分,项目坐标,信息描述等
modelVersion:pom文件的模型版本
关于group id和artifact id,为了便于多人多模块协同开发管理(以后会讲),建议使用以下命名规范
group id:com.公司名.项目名
artifact id:功能模块名
packaging:项目打包的后缀,war是web项目发布用的,默认为jar
version: artifact模块的版本
name和url:相当于项目描述,可删除
group id + artifact id +version :项目在仓库中的坐标
第二部分,引入jar包
这是创建项目时自动生成的,将junit-3.8.1.jar引入到项目中。
dependency:引入资源jar包到本地仓库,要引入更多资源就在<dependencies>中继续增加<dependency>
group id+artifact id+version:资源jar包在仓库中的坐标
scope:作用范围,test指该jar包仅在maven测试时使用,发布时会忽略这个包。需要发布的jar包可以忽略这一配置
刚开始本地仓库是空的,maven会从远程仓库自动下载这个jar到本地仓库,下载完后,就可以在项目中使用这个jar了
如果将<dependency>的内容删除,junit-3.8.1.jar也会自动消失,无法使用
第三部分,构建项目
build:项目构建时的配置
finalName:在浏览器中的访问路径,如果将它改成helloworld,再执行maven--update,这时运行项目的访问路径是
http://localhost:8080/helloworld/
而不是项目名的 http://localhost:8080/test
plugins:插件,之前篇章已经说过,第一个插件是用来设置java版本为1.7,第二个插件是我刚加的,用来设置编码为utf-8
group id+artifact
id+version:插件在仓库中的坐标
configuration:设置插件的参数值
第一部分,项目坐标,信息描述等
<modelVersion>4.0.0</modelVersion> <groupId>com.company.project</groupId> <artifactId>module</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>test Maven Webapp</name> <url>http://maven.apache.org</url>
modelVersion:pom文件的模型版本
关于group id和artifact id,为了便于多人多模块协同开发管理(以后会讲),建议使用以下命名规范
group id:com.公司名.项目名
artifact id:功能模块名
packaging:项目打包的后缀,war是web项目发布用的,默认为jar
version: artifact模块的版本
name和url:相当于项目描述,可删除
group id + artifact id +version :项目在仓库中的坐标
第二部分,引入jar包
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies>
这是创建项目时自动生成的,将junit-3.8.1.jar引入到项目中。
dependency:引入资源jar包到本地仓库,要引入更多资源就在<dependencies>中继续增加<dependency>
group id+artifact id+version:资源jar包在仓库中的坐标
scope:作用范围,test指该jar包仅在maven测试时使用,发布时会忽略这个包。需要发布的jar包可以忽略这一配置
刚开始本地仓库是空的,maven会从远程仓库自动下载这个jar到本地仓库,下载完后,就可以在项目中使用这个jar了
如果将<dependency>的内容删除,junit-3.8.1.jar也会自动消失,无法使用
第三部分,构建项目
<build> <finalName>helloworld</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.0.1</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
build:项目构建时的配置
finalName:在浏览器中的访问路径,如果将它改成helloworld,再执行maven--update,这时运行项目的访问路径是
http://localhost:8080/helloworld/
而不是项目名的 http://localhost:8080/test
plugins:插件,之前篇章已经说过,第一个插件是用来设置java版本为1.7,第二个插件是我刚加的,用来设置编码为utf-8
group id+artifact
id+version:插件在仓库中的坐标
configuration:设置插件的参数值
相关文章推荐
- 基本Hadoop Maven项目的pom.xml配置
- Maven项目pom.xml配置详解
- maven项目中自动下载jar包的pom.xml配置
- MyEclipse 配置maven项目pom.xml设置 上传项目到nexus私服,通过中转仓库下载插件,以及nexus的配置
- 大型Java项目中使用maven进行管理,pom.xml文件中build的配置
- maven web项目pom.xml配置
- nexus-3.6.0-02-unix.tar.gz安装(Centos下),maven setting.xml配置案例,项目root的pom.xml配置,parent-pom的pom.xml配置案例
- 整合SSM框架的maven项目pom.xml的常见配置
- 关于IDEA中项目pom.xml文件中jar报错,以及maven在IDEA中的配置!!!
- maven项目pom.xml配置json包
- maven项目中自动下载jar包的pom.xml配置
- Maven项目管理配置pom.xml留存
- Maven项目的pom.xml常见配置(Eclipse)
- Maven项目pom.xml配置详解
- Maven学习总结(29)——Maven项目的pom.xml中log4j2配置
- maven管理Spring MVC项目pom.xml配置
- Maven pom.xml 配置说明: 打jar包不包括指定资源文件和.class xml,配置不跑testCase,建pom父子项目
- 搭建Nexus Repository 3.6.0-02和配置apache-maven-3.5.2和本地的local Repository以及项目的pom.xml(IDEA 打包等)
- Maven项目的pom.xml配置
- maven项目的pom.xml常见配置详解