Glassfish中的Hibernate - Ejb3Configuration NoClassDefFoundError [英] Hibernate in Glassfish - Ejb3Configuration NoClassDefFoundError

查看:94
本文介绍了Glassfish中的Hibernate - Ejb3Configuration NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Hibernate库放入了Glassfish域以及Netbeans中项目的库集合中。 hibernate-entitymanager.jar 包含HibernatePersistence(调用堆栈中的最后一个类)和Ejb3Configuration,所以我非常难以理解为什么我会为Ejb3Configuration获取缺少的类错误。

  java.lang.NoClassDefFoundError:无法在org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory中初始化类org.hibernate.ejb.Ejb3Configuration 
(HibernatePersistence.java:130)
at com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java:149)
at com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java :84)
...


解决方案

I从来没有见过这个具体的错误信息,但我可以解释一下它的含义,并给出一个可能的原因。



 
java.lang.NoClassDefFoundError:无法初始化类org.hibernate.ejb。 Ejb3Configuration

并不意味着JVM找不到类 org.hibernate.ejb.Ejb3Configuration code>。这意味着JVM可以找到这个类,但它已经试过并且未能加载这个类。

这是文本无法初始化类。 .. 表示发生了这种情况。如果JVM根本找不到类,则可以使用类似于以下内容的类:

 
java.lang.NoClassDefFoundError:org / hibernate / ejb / Ejb3Configuration

另外,这也意味着您正在使用Java 6 - 在Java 5中,相应的异常没有消息。

以下两个类提供了这种行为的演示。类 Unloadable 不能被加载,因为它的静态初始化器总是抛出一个异常。我们尝试加载这个类,捕获结果的 ExceptionInInitializerError ,并尝试再次加载 Unloadable

  class Unloadable {
static {
if(true){throw new RuntimeException(); }



public class LoadingTest {
public static void main(String [] args)throws Exception {
try {
的Class.forName( 卸载的);
}
catch(ExceptionInInitializerError e){
try {
Class.forName(Unloadable);
}
catch(NoClassDefFoundError e2){
System.out.println(XXXXXXXXXXXXXXXXXXXXX);
e2.printStackTrace(System.out);
}
}
}
}

我运行类 LoadingTest ,我得到以下输出:

 
XXXXXXXXXXXXXXXXXXXXX
java.lang.NoClassDefFoundError:无法初始化类在java.lang.Class.forName0中可以加载
(本地方法)$ b $在java.lang.Class.forName(Class.java:169)
在LoadingTest.main(LoadingTest.java:14)

我不能说原因是什么导致加载 org.hibernate.ejb.Ejb3Configuration 失败。很可能是 Ejb3Configuration 本身依赖于类路径中缺少的类。通过 import /hibernate/entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java?view=markup&pathrev=14274rel =nofollow noreferrer> Ejb3Configuration 并确保所有不在 java。* javax。* 位于Glassfish和Netbeans可以看到的JAR中。



另外,我只能推测为什么JVM试图加载 Ejb3Configuration 两次。当类加载首次失败时,会引发异常(通常是 LinkageError 的某个子类)。这种类型的异常并不常被捕获,所以我最好的猜测是,类似下面的情况正在发生:

  try {
//一些加载Ejb3Configuration并失败的代码。
}
finally {
//一些代码也会加载Ejb3Configuration并失败。

$ / code>

如果中的代码最后 block抛出一个异常,这个异常将替换 try 块中抛出的任何异常。我建议这是因为类似的事情发生在这个问题上。此问题中发布的堆栈跟踪来自最后块。



如果我的答案仍然无效你可以请你发布你看到的整个堆栈跟踪吗?


I've put the Hibernate libraries in both the Glassfish domain and in the library collection of my project in Netbeans. hibernate-entitymanager.jar contains both HibernatePersistence (the last class in the call stack) and Ejb3Configuration, so I'm rather stumped as to why I get the missing class error for Ejb3Configuration.

java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ejb.Ejb3Configuration
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:130)
    at com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java:149)
    at com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java:84)
...

解决方案

I have never seen this specific error message before but I can explain a bit about what it means and give one possible cause.

The line

java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ejb.Ejb3Configuration

doesn't mean that the JVM could not find the class org.hibernate.ejb.Ejb3Configuration. It means that the JVM can find this class but it has already tried and failed to load this class.

It's the text Could not initialize class ... that indicates that this has happened. If the JVM couldn't find the class at all you'd get something like the following instead:

java.lang.NoClassDefFoundError: org/hibernate/ejb/Ejb3Configuration

As an aside, it also means you're using Java 6 - in Java 5 the corresponding exception has no message.

The following two classes provide a demonstration of this behaviour. The class Unloadable cannot be loaded because its static initializer always throws an exception. We attempt to load this class, catch the ExceptionInInitializerError that results, and attempt to load Unloadable again.

class Unloadable {
    static {
        if (true) { throw new RuntimeException(); }
    }
}

public class LoadingTest {
    public static void main(String[] args) throws Exception {
        try {
            Class.forName("Unloadable");
        }
        catch (ExceptionInInitializerError e) {
            try {
                Class.forName("Unloadable");
            }
            catch (NoClassDefFoundError e2) {
                System.out.println("XXXXXXXXXXXXXXXXXXXXX");
                e2.printStackTrace(System.out);
            }
        }
    }
}

When I run class LoadingTest, I get the following output:

XXXXXXXXXXXXXXXXXXXXX
java.lang.NoClassDefFoundError: Could not initialize class Unloadable
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at LoadingTest.main(LoadingTest.java:14)

I cannot say what is causing the original attempt to load org.hibernate.ejb.Ejb3Configuration to fail. It could well be that Ejb3Configuration itself depends on classes that are missing from the classpath. It might be worth going through the list of all the classes imported by Ejb3Configuration and ensuring that all those not under java.* or javax.* are within a JAR that Glassfish and Netbeans can see.

Also, I can only speculate as to why the JVM is attempting to load Ejb3Configuration twice. When the class loading fails for the first time, an exception (typically some subclass of LinkageError) is thrown. This type of exception isn't often caught, so my best guess is that something like the following is happening:

try {
    // Some code that loads Ejb3Configuration and fails.
}
finally {
    // Some code that also loads Ejb3Configuration and fails.
}

If the code in the finally block throws an exception, this exception will replace any exception thrown in the try block. I suggest this because a similar thing happened on this question. The stack trace posted in this question comes from within a finally block.

If my answer still doesn't help you, could you please post the entire stack trace you're seeing?

这篇关于Glassfish中的Hibernate - Ejb3Configuration NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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