配置Maven
安装并配置环境变量
<maven.apache.org>
检查JDK
注意:maven3.3.1需要jre7的支持
echo %JAVA_HOME%
java -version
配置环境变量
windows
控制面板 --> 系统和安全 --> 系统 --> 高级系统设置 --> 高级 --> 环境变量
添加环境变量MAVEN_HOME
,值为D:\work\maven\apache-maven-3.5.0
path环境变量添加:;%MAVEN_HOME%\bin
linux
配置本地仓库
**修改配置文件: %MAVEN_HOME%\conf\settings.xml **
在settings
节点下添加:
<localRepository>D:\work\maven\repo</localRepository>
以后,下载的maven资源就会存放到D:\work\maven\repo
中
配置远程仓库
**修改配置文件: %MAVEN_HOME%\conf\settings.xml **
在mirrors
节点下添加:
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<!-- <mirrorOf>*</mirrorOf> -->
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
下载archetype-catalog.xml
解决创建maven项目非常慢的问题
下载archetype-catalog.xml
文件,在远程仓库最下方
将文件archetype-catalog.xml
存放到本地仓库中
存入到本地仓库中的${MAVEN_HOME}\org\apache\maven\archetype\archetype-catalog\{version}
路径下
执行命令时,添加参数-DarchetypeCatalog=local
IDEA:Welcome to IntelliJ IDEA界面(不要在打开项目后设置) ---> configure ---> Settings ---> Build, Exception, Deployment ---> Build Tools ---> Maven ---> Runner ---> VM Options
项目创建命令
-X
为debug模式
mvn -X archetype:generate -DarchetypeCatalog=local -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.github.chencye -DartifactId=demo -Dversion=1.0.0
手动安装jar到本地仓库
以Oracle的jdbc驱动包ojbc示例
由于oracle授权问题,Maven3不提供Oracle JDBC driver,为了在Maven项目中应用Oracle JDBC driver,必须手动添加到本地仓库。
注意install:install-file不能有空格
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar -Dfile=D:\app\chencye\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar
配置下载源码与javadoc
修改配置文件: %MAVEN_HOME%\conf\settings.xml
在profiles
节点下添加:
<profile>
<id>autoDownloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
在profiles
节点后面添加:
<activeProfiles>
<activeProfile>autoDownloadSources</activeProfile>
</activeProfiles>
eclipse
Window > Preferences > Maven
勾选以下两个选项:
Download Artifact Sources
Download Artifact JavaDoc
IDEA
Settings --> Build, Execution, Deployment --> Build Tools --> Maven --> Importing --> Automatically download
配置默认jdk
修改配置文件: %MAVEN_HOME%\conf\settings.xml
在profiles
节点下添加:
<profile>
<id>defualtJDK</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
在activeProfiles
节点下添加:
<activeProfile>defualtJDK</activeProfile>