Birt 4.6.0-20160607 为 OracleDriver 抛出 ClassNotFoundException
Birt 4.6.0-20160607 throws ClassNotFoundException for OracleDriver
我有一个使用 Birt 4.6 的 naven 应用程序。低于我的依赖关系。
<dependency>
<groupId>org.eclipse.birt.ojdbc</groupId>
<artifactId>odajdbc</artifactId>
<version>4.6.0-201606072122</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.6.0-20160607</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.apache.xerces</artifactId>
</exclusion>
<exclusion>
<artifactId>org.apache.poi</artifactId>
<groupId>org.eclipse.birt.runtime</groupId>
</exclusion>
</exclusions>
</dependency>
我能够连接到数据库并生成报告。这些都是好消息。
不幸的是,我在我的日志文件中注意到抛出了一个异常。异常可以在下面看到
2017-01-10 14:57:15,446 SEVERE [org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager] (default task-6) DriverClassLoader failed to load class: oracle.jdbc.driver.OracleDriver: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at org.eclipse.birt.core.framework.URLClassLoader.findClass1(URLClassLoader.java:188)
at org.eclipse.birt.core.framework.URLClassLoader.run(URLClassLoader.java:156)
at org.eclipse.birt.core.framework.URLClassLoader.run(URLClassLoader.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.birt.core.framework.URLClassLoader.findClass(URLClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadExtraDriver(JDBCDriverManager.java:1064)
at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.findDriver(JDBCDriverManager.java:859)
at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadAndRegisterDriver(JDBCDriverManager.java:986)
at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadAndRegisterDriver(JDBCDriverManager.java:958)
at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.doConnect(JDBCDriverManager.java:285)
at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.getConnection(JDBCDriverManager.java:236)
at org.eclipse.birt.report.data.oda.jdbc.Connection.connectByUrl(Connection.java:254)
at org.eclipse.birt.report.data.oda.jdbc.Connection.open(Connection.java:163)
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConnection.open(OdaConnection.java:250)
at org.eclipse.birt.data.engine.odaconsumer.ConnectionManager.openConnection(ConnectionManager.java:165)
at org.eclipse.birt.data.engine.executor.DataSource.newConnection(DataSource.java:224)
at org.eclipse.birt.data.engine.executor.DataSource.open(DataSource.java:212)
at org.eclipse.birt.data.engine.impl.DataSourceRuntime.openOdiDataSource(DataSourceRuntime.java:217)
at org.eclipse.birt.data.engine.impl.QueryExecutor.openDataSource(QueryExecutor.java:437)
at org.eclipse.birt.data.engine.impl.QueryExecutor.prepareExecution(QueryExecutor.java:325)
at org.eclipse.birt.data.engine.impl.PreparedQuery.doPrepare(PreparedQuery.java:463)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.produceQueryResults(PreparedDataSourceQuery.java:190)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:178)
at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery.execute(PreparedOdaDSQuery.java:179)
at org.eclipse.birt.report.data.adapter.impl.DataRequestSessionImpl.execute(DataRequestSessionImpl.java:651)
at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:152)
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:286)
at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1947)
at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)
at org.eclipse.birt.report.engine.executor.TableItemExecutor.execute(TableItemExecutor.java:62)
at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)
at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)
at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92)
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:100)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:181)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)
由于某种原因,JDBCDriverManager 努力寻找正确的驱动程序,抛出异常,最终找到连接到数据库的驱动程序并生成报告。
我对 JDBCDriverManager 进行了调试,希望下面的信息对您有所帮助。
- 应用程序通过 JDBCDriverManager 的 doConnect() 函数。里面有 Connection getJndiDSConnection( driverClass, jndiNameUrl, connectionProperties ); returns 无效 。 doConnect 中的 getJndiDSConnection 也会发生同样的情况。还有 returns null
- 然后是loadAndRegisterDriver( driverClass, driverClassPath );使用以下参数调用 oracle.jdbc.driver.OracleDriver 和 null
- 在 loadAndRegisterDriver 中,使用以下参数调用 findDriver( className, driverClassPath, refreshClassLoader ) oracle.jdbc.driver.OracleDriver , null, 假
- 下一步 driverClass = loadExtraDriver( className, true, refresh, driverClassPath );使用 oracle.jdbc.driver.OracleDriver 、 true 、 false 、 null 调用,抛出上面提到的 ClassNotFoundException 。
- 最后一步,我们仍然在 findDriver 方法中,其中 driver = this.getDriverInstance( driverClass, refresh );方法被调用,最后 returns oracle.jdbc.driver.OracleDriver 。
第 5 步之后一切正常。正如我所提到的,异常只出现一次,但仍然会创建与数据库的连接并生成报告。在那之后,无论我创建报告多少次,都不会再抛出异常。
我想在这里添加一些关于 findDriver 方法的更多信息。此方法尝试以多种方式获取驱动程序。首先是
// Driver not in plugin class path; find it in drivers directory
driverClass = loadExtraDriver( className, true, refresh, driverClassPath );
returns null 然后尝试从上下文中获取驱动程序
driverClass = Class.forName( className, true, Thread.currentThread( ).getContextClassLoader());
这次终于实现了找回驱动。
我错过了什么?很明显它不能从插件加载它,因为我没有任何插件目录。有没有办法克服这个例外?
正如 Mark 所提到的,没有必要将 org.eclipse.birt.ojdbc 添加为依赖项。我停止使用 org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122.jar 并使用我的本地 ojdbc 驱动程序。
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
</dependency>
以上修复了我们在第一次尝试加载驱动程序时遇到的异常。
在 Birt Viewer 文件夹(Web/App 服务器端)的 WEB-INF
路径下添加 ojdbc7.jar
解决了我的问题:
[1] ../lib
[2] ../platform/plugins/org.eclipse.birt.report.data.oda.jdbc_<VERSION>/drivers
日志
在上面添加 [2] 之前(只有 [1]):
20-Mar-2017 14:12:26.752 SEVERE [http-nio-8080-exec-4] org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadExtraDriver DriverClassLoader failed to load class: oracle.jdbc.driver.OracleDriver java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
在上面添加 [2] 之后(只有 [1]):
20-Mar-2017 14:49:42.196 INFO [http-nio-8080-exec-4] org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager$DriverClassLoader.refreshFileURL JDBCDriverManager: found JAR file ojdbc7.jar. URL=file:../WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122/drivers/ojdbc7.jar
我有一个使用 Birt 4.6 的 naven 应用程序。低于我的依赖关系。
<dependency>
<groupId>org.eclipse.birt.ojdbc</groupId>
<artifactId>odajdbc</artifactId>
<version>4.6.0-201606072122</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.6.0-20160607</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.apache.xerces</artifactId>
</exclusion>
<exclusion>
<artifactId>org.apache.poi</artifactId>
<groupId>org.eclipse.birt.runtime</groupId>
</exclusion>
</exclusions>
</dependency>
我能够连接到数据库并生成报告。这些都是好消息。
不幸的是,我在我的日志文件中注意到抛出了一个异常。异常可以在下面看到
2017-01-10 14:57:15,446 SEVERE [org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager] (default task-6) DriverClassLoader failed to load class: oracle.jdbc.driver.OracleDriver: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver at org.eclipse.birt.core.framework.URLClassLoader.findClass1(URLClassLoader.java:188) at org.eclipse.birt.core.framework.URLClassLoader.run(URLClassLoader.java:156) at org.eclipse.birt.core.framework.URLClassLoader.run(URLClassLoader.java:1) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.birt.core.framework.URLClassLoader.findClass(URLClassLoader.java:151) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadExtraDriver(JDBCDriverManager.java:1064) at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.findDriver(JDBCDriverManager.java:859) at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadAndRegisterDriver(JDBCDriverManager.java:986) at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadAndRegisterDriver(JDBCDriverManager.java:958) at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.doConnect(JDBCDriverManager.java:285) at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.getConnection(JDBCDriverManager.java:236) at org.eclipse.birt.report.data.oda.jdbc.Connection.connectByUrl(Connection.java:254) at org.eclipse.birt.report.data.oda.jdbc.Connection.open(Connection.java:163) at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConnection.open(OdaConnection.java:250) at org.eclipse.birt.data.engine.odaconsumer.ConnectionManager.openConnection(ConnectionManager.java:165) at org.eclipse.birt.data.engine.executor.DataSource.newConnection(DataSource.java:224) at org.eclipse.birt.data.engine.executor.DataSource.open(DataSource.java:212) at org.eclipse.birt.data.engine.impl.DataSourceRuntime.openOdiDataSource(DataSourceRuntime.java:217) at org.eclipse.birt.data.engine.impl.QueryExecutor.openDataSource(QueryExecutor.java:437) at org.eclipse.birt.data.engine.impl.QueryExecutor.prepareExecution(QueryExecutor.java:325) at org.eclipse.birt.data.engine.impl.PreparedQuery.doPrepare(PreparedQuery.java:463) at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.produceQueryResults(PreparedDataSourceQuery.java:190) at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:178) at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery.execute(PreparedOdaDSQuery.java:179) at org.eclipse.birt.report.data.adapter.impl.DataRequestSessionImpl.execute(DataRequestSessionImpl.java:651) at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:152) at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:286) at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1947) at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80) at org.eclipse.birt.report.engine.executor.TableItemExecutor.execute(TableItemExecutor.java:62) at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43) at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46) at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65) at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92) at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:100) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:181) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)
由于某种原因,JDBCDriverManager 努力寻找正确的驱动程序,抛出异常,最终找到连接到数据库的驱动程序并生成报告。
我对 JDBCDriverManager 进行了调试,希望下面的信息对您有所帮助。
- 应用程序通过 JDBCDriverManager 的 doConnect() 函数。里面有 Connection getJndiDSConnection( driverClass, jndiNameUrl, connectionProperties ); returns 无效 。 doConnect 中的 getJndiDSConnection 也会发生同样的情况。还有 returns null
- 然后是loadAndRegisterDriver( driverClass, driverClassPath );使用以下参数调用 oracle.jdbc.driver.OracleDriver 和 null
- 在 loadAndRegisterDriver 中,使用以下参数调用 findDriver( className, driverClassPath, refreshClassLoader ) oracle.jdbc.driver.OracleDriver , null, 假
- 下一步 driverClass = loadExtraDriver( className, true, refresh, driverClassPath );使用 oracle.jdbc.driver.OracleDriver 、 true 、 false 、 null 调用,抛出上面提到的 ClassNotFoundException 。
- 最后一步,我们仍然在 findDriver 方法中,其中 driver = this.getDriverInstance( driverClass, refresh );方法被调用,最后 returns oracle.jdbc.driver.OracleDriver 。
第 5 步之后一切正常。正如我所提到的,异常只出现一次,但仍然会创建与数据库的连接并生成报告。在那之后,无论我创建报告多少次,都不会再抛出异常。
我想在这里添加一些关于 findDriver 方法的更多信息。此方法尝试以多种方式获取驱动程序。首先是
// Driver not in plugin class path; find it in drivers directory
driverClass = loadExtraDriver( className, true, refresh, driverClassPath );
returns null 然后尝试从上下文中获取驱动程序
driverClass = Class.forName( className, true, Thread.currentThread( ).getContextClassLoader());
这次终于实现了找回驱动。
我错过了什么?很明显它不能从插件加载它,因为我没有任何插件目录。有没有办法克服这个例外?
正如 Mark 所提到的,没有必要将 org.eclipse.birt.ojdbc 添加为依赖项。我停止使用 org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122.jar 并使用我的本地 ojdbc 驱动程序。
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
</dependency>
以上修复了我们在第一次尝试加载驱动程序时遇到的异常。
在 Birt Viewer 文件夹(Web/App 服务器端)的 WEB-INF
路径下添加 ojdbc7.jar
解决了我的问题:
[1] ../lib
[2] ../platform/plugins/org.eclipse.birt.report.data.oda.jdbc_<VERSION>/drivers
日志
在上面添加 [2] 之前(只有 [1]):
20-Mar-2017 14:12:26.752 SEVERE [http-nio-8080-exec-4] org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadExtraDriver DriverClassLoader failed to load class: oracle.jdbc.driver.OracleDriver java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
在上面添加 [2] 之后(只有 [1]):
20-Mar-2017 14:49:42.196 INFO [http-nio-8080-exec-4] org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager$DriverClassLoader.refreshFileURL JDBCDriverManager: found JAR file ojdbc7.jar. URL=file:../WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122/drivers/ojdbc7.jar