gradle jettyrun oracle找不到合适的驱动程序 [英] gradle jettyrun oracle no suitable driver found

查看:257
本文介绍了gradle jettyrun oracle找不到合适的驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个多项目春天(网络)项目。它开始很好,但只要我想查询数据库我得到一个

 在org.springframework.jdbc.CannotGetJdbcConnectionException中嵌套:无法获得JDBC连接;嵌套异常是org.apache.commons.dbcp.SQLNestedException:
无法为连接URL'jdbc:oracle:thin // server:1521:XE'创建类'oracle.jdbc.OracleDriver'的JDBC驱动程序:

我尝试了很多东西:我确定ojdbc.jar在我的项目中(不是maven回购的一部分,所以我使用gradle加载它,比如

 编译文件('lib / websphere_apis.jar','lib / ojdbc14.jar')

在我的sub(不是web)或我的web项目中。

当我用 gradle war

生成它们时,获得了战争中的罐子。使用

  jettyRun {
additionalRuntimeJars = files('lib / ojdbc14.jar')将jet添加到jettyRun配置中
}

我有点怀疑文件stmt 是正确的,但它仍然不起作用。



我也在SO上发现我应该放置$ / $>

  providedRuntime文件($ projectDir /../ lib / ojdbc14.jar)

作为标准依赖关系,但对我仍然不起作用。我已经使用了postgres驱动程序的jar文件,之后我可以将其作为一个依赖文件包含在其中。

解决方案

使用JDBC .jar文件不小心在类路径中加载.jar的位置,您可能会看到类似于您所看到的错误。如果您想确定,请将类路径上的.jar作为参数传递给调用该程序的主JVM。原因是您需要确保.jar类文件在默认JVM类加载器中加载。如果试图通过其他方式动态加载JDBC .jars(或许甚至是OSGI),或者像Tomcat那样通过自定义类加载器动态加载,那么您可能会遇到类加载器问题。


This is a kind of driving me nuts, I found some similar questions here on SO but I can't get it to work.

I have a multi project spring (web) project. It starts fine, but as soon as I want to query the db I get a

Nested in org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: 
Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc:oracle:thin//server:1521:XE':

I tried many things: I made sure the ojdbc.jar is inside my project (not part of maven repo so I loaded it with gradle like

compile files('lib/websphere_apis.jar','lib/ojdbc14.jar') 

in my sub (not web) or in my web project.

Which gets the jars inside war when I generate them with with gradle war

I tried adding the jars to the jettyRun configuration with

jettyRun {
   additionalRuntimeJars = files('lib/ojdbc14.jar')
}

I'm a bit in doubt whether the files stmt is correct but still it doesn't work.

I also found on SO that I should put

   providedRuntime files("$projectDir/../lib/ojdbc14.jar")

inside my webapp as a standard dependency but that still doesn't work for me. I have used postgres driver jars before which I could just include as a dependency.

解决方案

With JDBC .jar files, if you are not careful about where you load the .jar on the classpath, you might get an error like what you are seeing. If you want to be sure, pass the .jar on the classpath as an argument to the main JVM that is calling the program. The reason is that you need to make sure the .jar class files are loaded in the "default JVM classloader". If you try to load JDBC .jars dynamically through other means ( perhaps even as OSGI) , or dynamically loaded by custom classloader like Tomcat has, then you could get class loader issues.

这篇关于gradle jettyrun oracle找不到合适的驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆