一、maven的安装配置
注意:在进行如下配置之前,有个前提是你的java的jdk安装配置正确才行
1、首先,下载maven,网址http://maven.apache.org/download.cgi
2、解压到本地文件夹下,然后配置环境变量即可,我的是:(当然安装目录的文件夹命名建议用英文,我这有点不合适哈)
D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9
配置开始------->
桌面右键——此电脑——属性,上图:
打开高级系统设置:
点击右下角环境变量,配置如下:
MAVEN_HOME=D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9
PATH=%maven_home%in
小插曲,我在配置MAVEN_HOME=D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9的时候出现些问题,我的目录之前总是选择在了是两个这D:java软件安装资源汇总maven建项目apache-maven-3.3.9-bin这一级,然后在测试mvn -v时总控制台总是说:mvn不是内部或外部命令,也不是可运行的程序或批处理文件,这是因为windows找不到mvn的执行脚本。一定要见到如下的目录包,然后在选择对应的路径,就正确了。
测试 如下正确完成配置
C:Userslitan>mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9in..
Java version: 1.7.0_17, vendor: Oracle Corporation
Java home: D:javajavajdk1.7jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 8", version: "6.2", arch: "amd64", family: "windows"
二、在maven项目中安装oracle的jar包
现在我们引入oracle数据库,因为oracle不是开源的,所以Maven不提供Oracle JDBC driver,这样导致我们在pom.xml直接配置oracle时候出错:Missing artifact oracle:ojdbc14:jar:10.2.0.4
为了在Maven项目中应用Oracle JDBC driver,必须手动添加到本地仓库。
注意:若要正确安装该包,一定要把安装命令写正确,正确的如下(后面补充安装时候的错误):
D:java软件安装资源汇总java连接数据库的架包ojdbc14jar>mvn install:install-file -DgroupId=ojdbc -DartifactId=ojdbc14 -Dversion=10.2.0.4 -Dpackaging=jar -Dfile=ojdbc14.jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing D:java软件安装资源汇总java连接数据库的架包ojdbc14jarojdbc14.jar to C:Userslitan.m2
epositoryojdbcojdbc1410.2.0.4ojdbc14-10.2.0.4.jar
[INFO] Installing C:UserslitanAppDataLocalTempmvninstall5306757249047290117.pom to C:Userslitan.m2
epositoryojdbcojdbc1410.2.0.4ojdbc14-10.2.0.4.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.848 s
[INFO] Finished at: 2018-01-20T14:00:33+08:00
[INFO] Final Memory: 6M/153M
[INFO] ------------------------------------------------------------------------
=======================================================华丽分割线=========================================================
安装时的错误,总是报的错如下,重点错误在于标红且下划线部分,跟上面对照就明白错在哪里了,Dfile应该直接用jar名,这里实在该目录下(黄线部分,之前在c:/user/litan>下运行也总是失败,报错基本相同蓝色部分的提示)运行的,如果直接在
D:java软件安装资源汇总java连接数据库的架包ojdbc14jar>mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4 -Dpackaging=jar -Dfile=D:java软件安装资源汇总java连接数据库的架包ojdbc14 java连接oracle.jar包ojdbc14.jar
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.103 s
[INFO] Finished at: 2018-01-20T13:58:20+08:00
[INFO] Final Memory: 5M/121M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (D:java软件安装资源 汇总java连接数据库的架包ojdbc14jar). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
此时,我在pom.xml中添加配置如下:
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4</version>
</dependency>
发现仍然报错Missing artifact oracle:ojdbc14:jar:10.2.0.4,查找原因,是因为我安装时的groupId和我添加依赖时用的不一致,所以当然找不到喽,修正为ojdbc以后,OK。报错解除。一定要细心哦
<dependency>
<groupId>ojdbc</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4</version>
</dependency>