Oracle JDBC driver Maven配置

question:

maven project, add data source in spring, call error:

org.springframework.jdbc.CannotGetJdbcConnectionException  

Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver"

 

analyze:

Although adding the ojdbc dependency in maven, it still shows that it cannot be loaded. Because the maven central library cannot be loaded directly due to certificate issues, it needs to be manually loaded into the local maven library.

solve:

http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/

1. Get Oracle JDBC Driver

 

Two ways to get the Oracle jdbc driver :

  1. Oracle.com
  2. Oracle database installed folder, for example, “{ORACLE_HOME}\jdbc\lib\ojdbc6.jar

2. Install It

To install your Oracle jdbc driver, issue following command :

mvn install:install-file -Dfile={Path/to/your/ojdbc.jar} -DgroupId=com.oracle 
-DartifactId=ojdbc14 -Dversion=11.2.0 -Dpackaging=jar

See following full example :

D:\>mvn install:install-file -Dfile=D:\app\mkyong\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar 
-DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-pom ---
[INFO] Installing D:\app\mkyong\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar to 
D:\maven\repo\com\oracle\ojdbc6\11.2.0\ojdbc6-11.2.0.jar
[INFO] Installing C:\Users\mkyong\AppData\Local\Temp\mvninstall9153984116424557894.pom 
to D:\maven\repo\com\oracle\ojdbc6\11.2.0\ojdbc6-11.2.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.279s
[INFO] Finished at: Thu Apr 21 19:56:37 SGT 2011
[INFO] Final Memory: 2M/4M
[INFO] ------------------------------------------------------------------------

 

3. pom.xml

 

Now, you can reference it by declares following Oracle details in your pom.xml.

File: pom.xml

<project...> 
 
	<dependencies>>
 
		<!-- ORACLE database driver -->
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc14</artifactId>
			<version>10.2.0.4</version>
		</dependency>
 
	</dependencies>
</project>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326059517&siteId=291194637