Birt 4.6.0-20160607为OracleDriver

时间:2017-01-10 13:15:00

标签: maven java-ee jdbc birt ojdbc

我有一个使用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](默认任务-6)DriverClassLoader无法加载类:oracle.jdbc.driver.OracleDriver :java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver       在org.eclipse.birt.core.framework.URLClassLoader.findClass1(URLClassLoader.java:188)       在org.eclipse.birt.core.framework.URLClassLoader $ 1.run(URLClassLoader.java:156)       在org.eclipse.birt.core.framework.URLClassLoader $ 1.run(URLClassLoader.java:1)       at java.security.AccessController.doPrivileged(Native Method)       在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)       在java.lang.Class.forName(Class.java:348)       在org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadExtraDriver(JDBCDriverManager.java:1064)       在org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.findDriver(JDBCDriverManager.java:859)       在org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadAndRegisterDriver(JDBCDriverManager.java:986)       在org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.loadAndRegisterDriver(JDBCDriverManager.java:958)       在org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.doConnect(JDBCDriverManager.java:285)       在org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.getConnection(JDBCDriverManager.java:236)       在org.eclipse.birt.report.data.oda.jdbc.Connection.connectByUrl(Connection.java:254)       在org.eclipse.birt.report.data.oda.jdbc.Connection.open(Connection.java:163)       在org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConnection.open(OdaConnection.java:250)       在org.eclipse.birt.data.engine.odaconsumer.ConnectionManager.openConnection(ConnectionManager.java:165)       在org.eclipse.birt.data.engine.executor.DataSource.newConnection(DataSource.java:224)       在org.eclipse.birt.data.engine.executor.DataSource.open(DataSource.java:212)       在org.eclipse.birt.data.engine.impl.DataSourceRuntime.openOdiDataSource(DataSourceRuntime.java:217)       在org.eclipse.birt.data.engine.impl.QueryExecutor.openDataSource(QueryExecutor.java:437)       在org.eclipse.birt.data.engine.impl.QueryExecutor.prepareExecution(QueryExecutor.java:325)       在org.eclipse.birt.data.engine.impl.PreparedQuery.doPrepare(PreparedQuery.java:463)       在org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.produceQueryResults(PreparedDataSourceQuery.java:190)       在org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:178)       在org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery.execute(PreparedOdaDSQuery.java:179)       在org.eclipse.birt.report.data.adapter.impl.DataRequestSessionImpl.execute(DataRequestSessionImpl.java:651)       在org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:152)       在org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:286)       在org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1947)       在org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)       在org.eclipse.birt.report.engine.executor.TableItemExecutor.execute(TableItemExecutor.java:62)       在org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)       在org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)       在org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)       在org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)       在org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92)       在org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:100)       在org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:181)       在org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)

由于某种原因,JDBCDriverManager努力寻找正确的驱动程序,抛出异常,最终发现驱动程序连接到数据库并生成报告。

我在JDBCDriverManager上进行了调试,并希望下面的信息确实有所帮助。

  1. 应用程序通过doConnect()函数JDBCDriverManager。里面有Connection getJndiDSConnection(driverClass,jndiNameUrl,connectionProperties); 返回null 。 doConnect中的getJndiDSConnection也是如此。也返回null
  2. 然后是loadAndRegisterDriver(driverClass,driverClassPath);使用以下参数调用 oracle.jdbc.driver.OracleDriver null
  3. 在loadAndRegisterDriver中,使用以下参数调用findDriver(className,driverClassPath,refreshClassLoader) oracle.jdbc.driver.OracleDriver null false
  4. 在下一步中,driverClass = loadExtraDriver(className,true,refresh,driverClassPath);使用 oracle.jdbc.driver.OracleDriver,true,false,null 调用,它会抛出上面提到的 ClassNotFoundException
  5. 最后一步,我们仍然在findDriver方法里面,其中driver = this.getDriverInstance(driverClass,refresh);调用方法,最后返回oracle.jdbc.driver.OracleDriver。
  6. 在第5步之后一切正常。正如我所提到的,异常只出现一次,并且仍然创建了与数据库的连接并生成了报告。在那之后,无论我创建报告多少次,都不会再次抛出异常。

    我想在这里添加一些关于findDriver方法的更多信息。此方法尝试以多种方式获取驱动程序。首先是

    // Driver not in plugin class path; find it in drivers directory
    driverClass = loadExtraDriver( className, true, refresh, driverClassPath );
    

    返回null,然后尝试从上下文中获取驱动程序

    driverClass = Class.forName( className, true, Thread.currentThread( ).getContextClassLoader()); 
    

    这次它最终实现了检索驱动程序。

    我缺少什么?很明显它无法从插件中加载它,因为我没有任何插件目录。有没有办法克服这个例外?

2 个答案:

答案 0 :(得分:1)

正如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>

上面修复了第一次尝试加载驱动程序时遇到的异常。

答案 1 :(得分:0)

在Birt Viewer文件夹(Web / App Server端)的ojdbc7.jar路径下添加WEB-INF解决了我的问题:

[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