将下载的压缩包解压,并配置环境变量css
在~/.m2/setting.xml中进行配置,配置以下:java
<proxies>
<proxy>
<!-- 惟一标识 -->
<id></id>
<!-- 是否激活 boolean -->
<active></active>
<!-- 代理协议,一般使用HTTP -->
<protocol></protocol>
<!-- 主机名 -->
<host></host>
<!-- 端口 -->
<port></port>
<!-- 认证用户名 -->
<username></username>
<!-- 认证密码 -->
<password></password>
<!-- 设置不须要代理的域名 -->
<nonProxyHosts></nonProxyHosts>
</proxy>
</proxies>
复制代码
中央仓库地址: repo1.maven.org/maven2
设置本地仓库地址web
在setting.xml中设置
<localRepository></localRepository>
复制代码
远程仓库配置请参考代码 远程仓库认证信息配置以下:apache
在setting.xml中配置
<servers>
<server>
<!-- pom文件中远程仓库的ID -->
<id></id>
<!-- 用户名 -->
<username></username>
<!-- 密码 -->
<password></password>
</server>
</servers>
复制代码
如需配置镜像服务,则在setting.xml中配置以下app
<mirrors>
<mirror>
<!-- 镜像地址惟一标识 -->
<id></id>
<!-- 镜像描述 -->
<name></name>
<!-- 镜像地址 -->
<url></url>
<!-- 镜像代理地址,经过ID表示,*表示全部 -->
<mirrorOf></mirrorOf>
</mirror>
</mirros>
复制代码
<project>
<!-- 固定值 -->
<modelVersion>4.0.0</modelVersion>
<!-- 所属项目,必选 -->
<groupId>com.xxx</groupId>
<!-- 模块名称,必选 -->
<artifactId>xxx</artifactId>
<!-- 版本,SNAPSHOT表示快照,必选 -->
<version>0.0.1-SNAPSHOT</version>
<!-- 打包方式,默认为jar,可选 -->
<packaging>jar</packaging>
<name></name>
<url>http://maven.apache.org</url>
<!-- 若是须要引用父maven,则使用以下标签 -->
<parent>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<!-- 父类pom文件相对位置,默认为../pom.xml,即在上一层目录中 -->
<relativePath></relativePath>
</parent>
<!-- 属性 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<!-- 依赖的jar包groupId -->
<groupId></groupId>
<!-- 依赖的jar包artifactId -->
<artifactId></artifactId>
<!-- 依赖的jar包版本号 -->
<version></version>
<!-- 依赖的范围 -->
<scope></scope>
<!-- 标记依赖是否可选,true表示该依赖只对当前项目有效,不会传递 -->
<optional></optional>
<!-- 排除传递依赖 -->
<exclusions>
<exclusion>
<groupId></groupId>
<artifactId></artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<!-- 远程仓库配置 -->
<repositories>
<repository>
<!-- 远程仓库惟一标识 -->
<id></id>
<!-- 远程仓库描述 -->
<name></name>
<!-- 远程仓库地址 -->
<url></url>
<!-- 远程仓库发布版本下载支持 -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 远程仓库快照版本下载支持 -->
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<!-- 远程插件仓库配置 -->
<pluginRepositories>
<pluginRepository>
<id></id>
<name></name>
<url></url>
</pluginRepository>
</pluginRepositories>
<build>
<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>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
复制代码
便可以使用Maven中的属性值替换配置文件中的值webapp
在pom.xml中配置以下maven
<!-- 资源文件过滤 -->
<build>
<resources>
<resource>
<!-- 资源路径 -->
<directory></directory>
<filtering>true</filtering>
<!-- 排除的资源文件 -->
<excludes>
<exclude>src/main/filter</exclude>
</excludes>
</resource>
</resources>
</build>
<!-- 针对不一样环境的不一样配置 -->
<profiles>
<profile>
<id>dev</id>
<!-- 配置的属性值 -->
<properties></properties>
<!-- 默认激活 -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<!-- 针对单个profile资源过滤 -->
<build>
<filters>
<filter>src/main/filter/dev_filter.properties</filter>
</filters>
</build>
</profile>
</profiles>
复制代码
新建项目,之包含pom.xml,其中<packaging>元素设置为pom,在聚合中,最主要的元素为ui
<modules>
<!-- 聚合的模块名称 -->
<module></module>
...
<module></module>
</modules>
复制代码
继承与聚合同样,<packaging>元素设置为pom,子pom若是须要继承父pom中的元素,则在子pom中配置<parent>元素,具体参考配置,可继承的元素以下:url
在父模块中,元素<dependencyManagement>既能让子模块继承到父模块的依赖配置,又能保证子模块依赖使用的灵活性,由于该元素下的依赖声明不会引入实际的依赖,不过它可以约束dependencies的依赖使用,即子类要重写父依赖的groupId和artifactId元素spa
编译插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- 支持的java版本 -->
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 对web资源进行过滤 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<!-- 过滤的目录 -->
<includes>
<include>* */*.css</include>
<include>* */*.js</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
复制代码
mvn dependency:list 查看当前项目已解析依赖
mvn dependency:tree 查看当前项目依赖树
mvn dependency:analyze 分析当前项目依赖树\
在setting.xml配置镜像,同时配置私服地址以下
<profiles>
<profile>
<id>nexus</id>
<!-- 以下配置请参考Maven元素远程仓库配置 -->
<repository>
</repository>
</profile>
</profiles>
<!-- 激活的私服ID -->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeprofiles>
复制代码