2012-05-10 64 views
1

我得到這個錯誤,當我試圖配置我的會話工廠, 根據谷歌的結果把javaee-api放在提供的範圍內應該解決問題,但它並不:/javax /驗證/驗證錯誤與javax/javaee-api-6.0

充分的pom.xml [代碼]

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.me.app</groupId> 
    <artifactId>PersonnesServices</artifactId> 
    <version>1.0</version> 
    <packaging>jar</packaging> 
    <name>PersonnesServices</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <!-- Junit --> 
    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
     <scope>test</scope> 
    </dependency> 
    <!-- HIBERNATE --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>4.1.2</version> 
    </dependency> 

    <!-- HSQLDB --> 
    <dependency> 
     <groupId>org.hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
     <version>2.2.8</version> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 
    </dependencies> 

</project> 

[/代碼]

我的hibernate.cfg.xml

[代碼]

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
     "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 
     <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property> 
     <property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost</property> 
     <property name="hibernate.connection.username">sa</property> 
     <property name="connection.password"></property> 
     <!-- JDBC connection pool (use the built-in) --> 
     <property name="connection.pool_size">1</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property> 
     <property name="current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property> 
     <!-- Enable Hibernate's automatic session context management --> 
     <property name="hibernate.current_session_context_class">thread</property> 
     <!-- Disable the second-level cache --> 
     <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 
     <!-- Echo all executed SQL to stdout --> 
     <property name="show_sql">true</property> 
     <!-- Drop and re-create the database schema on startup --> 
     <property name="hbm2ddl.auto">create</property> 

     <property name="javax.persistence.validation.mode">none</property> 
     <!-- Mapping files --> 
     <mapping class="com.me.dto.Personne"/> 
     <mapping class="com.me.dto.Ecole"/> 
    </session-factory> 
</hibernate-configuration> 

[/代碼]

和我的錯誤:

[代碼]

Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/validation/Validation 
    at java.lang.ClassLoader.defineClass1(Native Method) 
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) 
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616) 
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) 
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) 
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:296) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138) 
    at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:115) 
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:304) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1741) 
    at com.csc.util.HibernateUtil.configureSessionFactory(HibernateUtil.java:15) 
    at com.csc.services.test.main(test.java:20) 

[/代碼]

任何你已經遇到這樣的問題? 謝謝。

+0

additionals信息:將‘測試’範圍使程序工作,但內置的(mvn clean install)失敗。 – Eildosa

回答

1

看看我用的JavaEE的Web-API 6這個問題,當我運行JUnit測試休眠。

我固定它替換:

<dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 

爲:

<dependency> 
    <groupId>org.jboss.spec</groupId> 
    <artifactId>jboss-javaee-6.0</artifactId> 
    <version>2.0.0.Final</version> 
    <type>pom</type> 
    <scope>provided</scope> 
</dependency> 
0

我有同樣的問題,同時運行JUnits並得到按照以下步驟解決: 1.添加下面的依賴上述休眠依賴

<dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.glassfish.main.extras</groupId> 
     <artifactId>glassfish-embedded-all</artifactId> 
     <version>3.1.2.2</version> 
     <scope>test</scope> 
    </dependency> 
  1. 我擰我的構建路徑,因此刪除「的.classpath」文件(日食>導航器),也行家>更新項目重置我的構建路徑

然後它的工作