org.springframework.webflow.util.RandomGuid上的java.lang.NoClassDefFoundError错误

时间:2023-01-17 18:06:01

I am sorry, my question is stupid, but I am not able to answer it, as a java illiterate. I run a tomcat (5) on CentOS5 (for a CAS server), and when I try to open this URL http://192.168.1.17:8080/cas-server-webapp-3.3.1/login I get this error :

对不起,我的问题很愚蠢,但作为一个java文盲,我无法回答它。我在CentOS5上运行一个tomcat(5)(用于CAS服务器),当我尝试打开这个URL时http://192.168.1.17:8080/cas-server-webapp-3.3.1/login我收到此错误:

first error: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.webflow.util.RandomGuid

第一个错误:java.lang.NoClassDefFoundError:无法初始化类org.springframework.webflow.util.RandomGuid

and root error: org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.webflow.util.RandomGuid

和root错误:org.springframework.web.util.NestedServletException:处理程序处理失败;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类org.springframework.webflow.util.RandomGuid

$CLASSPATH is empty, and it seems to be a problem, but I don't know what to put in it.

$ CLASSPATH是空的,这似乎是一个问题,但我不知道该放入什么。

EDIT: Jared is right, my hosts files defined 127.0.0.1 as localhost, and now it work very well!

编辑:Jared是对的,我的主机文件将127.0.0.1定义为localhost,现在它工作得很好!

5 个解决方案

#1


25  

It is important to keep two or three different exceptions strait in our head in this case:

在这种情况下,保持两到三个不同的例外是很重要的:

  1. java.lang.ClassNotFoundException This exception indicates that the class was not found on the classpath. This indicates that we were trying to load the class definition, and the class did not exist on the classpath.

    java.lang.ClassNotFoundException此异常指示在类路径中找不到该类。这表明我们正在尝试加载类定义,并且类在路径上不存在。

  2. java.lang.NoClassDefFoundError This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it. This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying again, but we're not even going to try to load it, because we failed loading it earlier. The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.

    java.lang.NoClassDefFoundError此异常指示JVM在其内部类定义数据结构中查找类的定义但未找到它。这不同于说它无法从类路径加载。通常这表明我们之前尝试从类路径加载一个类,但由于某种原因它失败了 - 现在我们再次尝试,但我们甚至都不会尝试加载它,因为我们之前没有加载它。较早的失败可能是ClassNotFoundException或ExceptionInInitializerError(表示静态初始化块中的失败)或任何其他问题。关键是,NoClassDefFoundError不一定是类路径问题。

That being said, another answer poster indicates that the RandomGUID requires a call to InetAddress.getLocalHost(). On many operating systems, this would trigger a host lookup that would use the hosts file (/etc/hosts on *NIX systems, %WINDOWS%/system32/drivers/etc/HOSTS on a Windows system.)

话虽这么说,另一个回答海报表明RandomGUID需要调用InetAddress.getLocalHost()。在许多操作系统上,这将触发主机查找,该主机查找将使用hosts文件(* NIX系统上的/ etc / hosts,Windows系统上的%WINDOWS%/ system32 / drivers / etc / HOSTS)。

I have seen similar errors quite frequently when that file incorrectly defines the localhost address. 127.0.0.1 should point to 'localhost' (and probably also localhost.localdomain.) It should NOT point to the actual host name of the machine (although for some reason, many older RedHat Linux installers liked to set it incorrectly.)

当该文件错误地定义localhost地址时,我经常看到类似的错误。 127.0.0.1应该指向'localhost'(也可能是localhost.localdomain。)它不应该指向机器的实际主机名(尽管由于某种原因,许多较旧的RedHat Linux安装程序喜欢错误地设置它。)

#2


1  

Nowadays, the environment variable $CLASSPATH should not be used; instead, the java application should have the classpath set on the command line.

现在,不应该使用环境变量$ CLASSPATH;相反,java应用程序应该在命令行上设置类路径。

However, in the case of tomcat and libraries used in the webapps, you simply put the JARs (for Spring) into the shared/lib/ folder of the tomcat installation.

但是,对于webapps中使用的tomcat和库,只需将JAR(用于Spring)放入tomcat安装的shared / lib /文件夹中即可。

#3


1  

NoClassDef: The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found. As you're missing a spring class I'd guess that you're missing one of the spring jar files.

NoClassDef:编译当前正在执行的类时存在搜索的类定义,但无法再找到该定义。因为你错过了一个春季班,我猜你错过了一个弹簧jar文件。

There are 2 places to put jars in tomcat, there's a global area (which in 5 is something like common/lib and is a bit different in tomcat6) and the area only for your webapp, which is webapps/mywebapp/WEB-INF/lib. The jars for your app should really go here, but if you're really perplexed and can't figure out any other way to make it work they'll work in the global (if you have only some of them in the global it might also break, as they might need a class in another jar and if one piece is in the local it won't work. This is especially true for spring libraries because there's a number of separate jars, not just one).

在tomcat中有两个放置jar的地方,有一个全局区域(在5中类似于common / lib,在tomcat6中有点不同)和仅适用于你的webapp的区域,即webapps / mywebapp / WEB-INF /库。你的应用程序的罐子应该真的到了这里,但是如果你真的很困惑并且无法找出任何其他方法来使它工作,它们将在全球范围内工作(如果你在全球范围内只有一些它可能也可以打破,因为他们可能需要另一个jar中的一个类,如果一个部分在本地,它将无法工作。对于Spring库尤其如此,因为有许多单独的jar,而不仅仅是一个)。

your CLASSPATH is a list of everywhere the jvm looks for classes. This could include directories of class files, or jar or zip files of classes, which are listed like directories. Tomcat should load that for you by using the above mentioned directories correctly.

你的CLASSPATH是jvm查找类的所有地方的列表。这可能包括类文件的目录,或类的jar或zip文件,它们列在目录中。 Tomcat应该正确地使用上面提到的目录为你加载。

#4


1  

The reason is failure to load class RandomGUID.

原因是无法加载类RandomGUID。

From looking at RandomGUID source, most of the chances that its static initializer failed at InetAddress.getLocalHost().

从查看RandomGUID源,其静态初始化程序在InetAddress.getLocalHost()失败的大部分机会。

Do you have some strange networking config on the host? For example, no or weird localhost definition in /etc/hosts ?

你在主机上有一些奇怪的网络配置吗?例如,/ etc / hosts中没有或奇怪的localhost定义?

#5


0  

If this appeared suddenly and unlogically to what you've been constructing, try renaming and renaming back classes that are referenced in an error log. This helped me in Netbeans several times.

如果这突然出现并且没有出现在您构建的内容中,请尝试重命名并重命名错误日志中引用的类。这让我在Netbeans中多次帮助过。

#1


25  

It is important to keep two or three different exceptions strait in our head in this case:

在这种情况下,保持两到三个不同的例外是很重要的:

  1. java.lang.ClassNotFoundException This exception indicates that the class was not found on the classpath. This indicates that we were trying to load the class definition, and the class did not exist on the classpath.

    java.lang.ClassNotFoundException此异常指示在类路径中找不到该类。这表明我们正在尝试加载类定义,并且类在路径上不存在。

  2. java.lang.NoClassDefFoundError This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it. This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying again, but we're not even going to try to load it, because we failed loading it earlier. The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.

    java.lang.NoClassDefFoundError此异常指示JVM在其内部类定义数据结构中查找类的定义但未找到它。这不同于说它无法从类路径加载。通常这表明我们之前尝试从类路径加载一个类,但由于某种原因它失败了 - 现在我们再次尝试,但我们甚至都不会尝试加载它,因为我们之前没有加载它。较早的失败可能是ClassNotFoundException或ExceptionInInitializerError(表示静态初始化块中的失败)或任何其他问题。关键是,NoClassDefFoundError不一定是类路径问题。

That being said, another answer poster indicates that the RandomGUID requires a call to InetAddress.getLocalHost(). On many operating systems, this would trigger a host lookup that would use the hosts file (/etc/hosts on *NIX systems, %WINDOWS%/system32/drivers/etc/HOSTS on a Windows system.)

话虽这么说,另一个回答海报表明RandomGUID需要调用InetAddress.getLocalHost()。在许多操作系统上,这将触发主机查找,该主机查找将使用hosts文件(* NIX系统上的/ etc / hosts,Windows系统上的%WINDOWS%/ system32 / drivers / etc / HOSTS)。

I have seen similar errors quite frequently when that file incorrectly defines the localhost address. 127.0.0.1 should point to 'localhost' (and probably also localhost.localdomain.) It should NOT point to the actual host name of the machine (although for some reason, many older RedHat Linux installers liked to set it incorrectly.)

当该文件错误地定义localhost地址时,我经常看到类似的错误。 127.0.0.1应该指向'localhost'(也可能是localhost.localdomain。)它不应该指向机器的实际主机名(尽管由于某种原因,许多较旧的RedHat Linux安装程序喜欢错误地设置它。)

#2


1  

Nowadays, the environment variable $CLASSPATH should not be used; instead, the java application should have the classpath set on the command line.

现在,不应该使用环境变量$ CLASSPATH;相反,java应用程序应该在命令行上设置类路径。

However, in the case of tomcat and libraries used in the webapps, you simply put the JARs (for Spring) into the shared/lib/ folder of the tomcat installation.

但是,对于webapps中使用的tomcat和库,只需将JAR(用于Spring)放入tomcat安装的shared / lib /文件夹中即可。

#3


1  

NoClassDef: The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found. As you're missing a spring class I'd guess that you're missing one of the spring jar files.

NoClassDef:编译当前正在执行的类时存在搜索的类定义,但无法再找到该定义。因为你错过了一个春季班,我猜你错过了一个弹簧jar文件。

There are 2 places to put jars in tomcat, there's a global area (which in 5 is something like common/lib and is a bit different in tomcat6) and the area only for your webapp, which is webapps/mywebapp/WEB-INF/lib. The jars for your app should really go here, but if you're really perplexed and can't figure out any other way to make it work they'll work in the global (if you have only some of them in the global it might also break, as they might need a class in another jar and if one piece is in the local it won't work. This is especially true for spring libraries because there's a number of separate jars, not just one).

在tomcat中有两个放置jar的地方,有一个全局区域(在5中类似于common / lib,在tomcat6中有点不同)和仅适用于你的webapp的区域,即webapps / mywebapp / WEB-INF /库。你的应用程序的罐子应该真的到了这里,但是如果你真的很困惑并且无法找出任何其他方法来使它工作,它们将在全球范围内工作(如果你在全球范围内只有一些它可能也可以打破,因为他们可能需要另一个jar中的一个类,如果一个部分在本地,它将无法工作。对于Spring库尤其如此,因为有许多单独的jar,而不仅仅是一个)。

your CLASSPATH is a list of everywhere the jvm looks for classes. This could include directories of class files, or jar or zip files of classes, which are listed like directories. Tomcat should load that for you by using the above mentioned directories correctly.

你的CLASSPATH是jvm查找类的所有地方的列表。这可能包括类文件的目录,或类的jar或zip文件,它们列在目录中。 Tomcat应该正确地使用上面提到的目录为你加载。

#4


1  

The reason is failure to load class RandomGUID.

原因是无法加载类RandomGUID。

From looking at RandomGUID source, most of the chances that its static initializer failed at InetAddress.getLocalHost().

从查看RandomGUID源,其静态初始化程序在InetAddress.getLocalHost()失败的大部分机会。

Do you have some strange networking config on the host? For example, no or weird localhost definition in /etc/hosts ?

你在主机上有一些奇怪的网络配置吗?例如,/ etc / hosts中没有或奇怪的localhost定义?

#5


0  

If this appeared suddenly and unlogically to what you've been constructing, try renaming and renaming back classes that are referenced in an error log. This helped me in Netbeans several times.

如果这突然出现并且没有出现在您构建的内容中,请尝试重命名并重命名错误日志中引用的类。这让我在Netbeans中多次帮助过。