在64位计算机上运行时出现NoClassDefFoundError

在64位计算机上运行时出现NoClassDefFoundError

问题描述:

在64位计算机上启动服务时,出现以下异常. 但是代码可以在32位计算机上正常运行.

I am getting the following exception while service startup on a 64bit Machine. But the code runs fine on a 32bit machine.

java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at org.springframework.context.support.GenericApplicationContext.<init (GenericApplicationContext.java:103)
    at org.springframework.context.support.GenericApplicationContext.<init>(GenericApplicationContext.java:125)
    at org.springframework.coral.CoralApplicationContext.<init>(CoralApplicationContext.java:41)
    at org.springframework.coral.CoralApplicationContext.<init>(CoralApplicationContext.java:35)
    at org.springframework.coral.DisposableApplicationContext.<init>(DisposableApplicationContext.java:16)
    at com.amazon.coral.spring.Launcher.<init>(Launcher.java:85)
    at com.amazon.coral.spring.Launcher.main(Launcher.java:56)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.commons.EmptyVisitor
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 19 more

除非您(或您使用的库)使用本机代码,否则底层平台很少是Java程序中的问题.

Unless you (or the libraries you use) are using native code, the underlying platform is very seldom the problem in Java programs.

来自NoClassDefFoundError的Javadoc(http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/NoClassDefFoundError.html):

From the Javadoc of NoClassDefFoundError (http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/NoClassDefFoundError.html):

如果Java虚拟机或ClassLoader实例尝试执行以下操作,则抛出该异常 加载类的定义(作为常规方法调用的一部分或 作为使用新表达式创建新实例的一部分),并且否 可以找到该类的定义.

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

搜索到的类定义在当前执行时存在 类已编译,但无法再找到该定义.

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

因此,在编译代码时就存在它,但是当您尝试在其他地方运行它时就不存在了.造成这种情况的最简单的最典型的原因是,错误地设置了类路径,通常是因为没有将包含所讨论类的jar文件放在类路径中.修改您的类路径定义并重新运行.

So it was present when the code was compiled, but not anymore when you try to run it elsewhere. The single-most typical reason for this is that the classpath is incorrectly set up, usually by not having the jar-file containing the class in question is not in the classpath. Revise your classpath definition and rerun.

如果您不熟悉类路径的工作原理,强烈建议您阅读Oracle Java教程.

If you are unfamiliar with how the classpath works I can strongly recommend reading up on the Oracle Java Tutorial.