org.springframework.webflow.util.RandomGuid 上的错误 java.lang.NoClassDefFoundError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/375332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error java.lang.NoClassDefFoundError on org.springframework.webflow.util.RandomGuid
提问by Cédric Girard
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/loginI get this error :
对不起,我的问题很愚蠢,但作为一个 java 文盲,我无法回答。我在 CentOS5(用于 CAS 服务器)上运行了一个 tomcat (5),当我尝试打开这个 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
和根错误: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,现在它工作得很好!
采纳答案by Jared
It is important to keep two or three different exceptions strait in our head in this case:
在这种情况下,在我们的脑海中保留两个或三个不同的异常是很重要的:
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.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.ClassNotFoundException
此异常表示在类路径中找不到该类。这表明我们正在尝试加载类定义,并且类路径上不存在该类。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()。在许多操作系统上,这会触发使用主机文件的主机查找(/etc/hosts
在 *NIX 系统上,%WINDOWS%/system32/drivers/etc/HOSTS
在 Windows 系统上。)
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 NOTpoint to the actual host name of the machine (although for some reason, many older RedHat Linux installers liked to set it incorrectly.)
当该文件错误地定义了本地主机地址时,我经常看到类似的错误。 127.0.0.1
应该指出的“localhost”(可能也是localhost.localdomain
。)应该不是指向机器的实际主机名(尽管因为某些原因,许多老RedHat Linux上安装喜欢正确设置它。)
回答by Michael Borgwardt
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/ 文件夹中。
回答by Steve B.
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:在编译当前执行的类时,搜索到的类定义存在,但不再找到该定义。由于您缺少 spring 类,我猜您缺少 spring 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).
有 2 个地方可以在 tomcat 中放置 jars,有一个全局区域(其中 5 个类似于 common/lib,在 tomcat6 中有点不同)和仅用于您的 webapp 的区域,即 webapps/mywebapp/WEB-INF/库。您的应用程序的 jars 应该真正放在此处,但是如果您真的很困惑并且无法找出任何其他方法来使其工作,它们将在全局中工作(如果您在全局中只有其中一些,它可能也会中断,因为他们可能需要另一个 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 应该通过正确使用上述目录为您加载它。
回答by Yoni Roit
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 source来看,其静态初始化程序在 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 定义?
回答by Zon
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 中帮助了我好几次。