尽管它被部署,但Jboss-as7无法找到oracle驱动程序

时间:2016-07-01 08:00:00

标签: java hibernate jboss

我正在使用hibernate从jboss-as7中的Web应用程序连接到数据库。这是我的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="HBOService">
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>

        <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
        <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
        <property name="hibernate.connection.username" value="hboweb"/>
        <property name="hibernate.connection.password" value="****"/>
</properties>

我还在我的jboss服务器中部署了ojdb6.jar,事实上我可以看到它在管理控制台的Manage Deployements选项卡中列出。

尝试启动应用程序时仍然收到此消息:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: HBOService] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
... 3 more
Caused by: org.hibernate.HibernateException: Specified JDBC Driver oracle.jdbc.OracleDriver class not found
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:104)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:234)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:91)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
... 9 more
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver from [Module "org.hibernate:main" from local module loader @778f9ba9 (roots: C:\Users\Developer1\Desktop\Development\Servers\jboss-as-7.1.1.Final\modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_79]
at java.lang.Class.forName(Class.java:191) [rt.jar:1.7.0_79]
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:101)
... 23 more

oracle.jdb.driver实际上是在classpath中吗?我怎么知道?

1 个答案:

答案 0 :(得分:0)

使用Jboss-server,jdbc驱动程序将从其模块类加载器加载,在您的情况下,它将扫描并从路径加载类
C:\用户\ Developer1 \桌面\发展\服务器\ jboss-as-7.1.1.Final \模块
直到oracle.jdb.driver包含在jar文件jdbc-oracle.jar或ojdbc6.jar中,因此您可以尝试在模块文件夹上面进行文件搜索。如果找不到该文件,可以根据以下指南将新模块添加到服务器中

1)下载ojdbc6-11.jar并将其放在文件夹中$JBOSS_HOME/modules/com/oracle/ojdbc6/main

2)在$ JBOSS_HOME / modules / com / oracle / ojdbc6 / main下创建了文件module.xml,这是文件的内容

<module xmlns="urn:jboss:module:1.0" name="com.oracle.ojdbc6">
  <resources>
    <resource-root path="ojdbc6.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
  </dependencies>
</module>

3)使用WEB-INF lib目录中的MANIFEST.MF文件添加对com.oracle.ojdbc6模块的依赖,内容为: 依赖关系:com.oracle.ojdbc6

可以使用以下Maven插件配置创建:

<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <configuration>
         <archive>
            <manifestEntries>
               <Dependencies>com.oracle.ojdbc6
</Dependencies>
            </manifestEntries>
         </archive>
      </configuration>
   </plugin>
</plugins>