为什么我在部署后收到 noclassdefounderror?

why am i getting the noclassdeffounderror after deploying?

部署 jar 并更改某个 class 文件后,我没有收到 classdefounderror。 当我通过 7zip 提取 jar 文件时,我能够在 jar 中看到 class 文件。

我还反编译了 .class 文件以查找任何错误,但没有得到任何东西。

在部署时,我只是将 .class 文件从 eclipse work space 拖到一个预先存在的 jar 文件中。这重要吗?

编译 jar 文件的 jdk 版本是否重要,因为我 运行 在 eclipse 中使用 jre 1.7,但我的部署环境是 jre 1.6?

我心目中的问题是添加到jar中的class是在不同版本的Java下编译的。我猜你是在 1.7 上编译的,而 12c 是 运行 1.7,而 11g 是 运行 1.6。在 1.6 中编译 class 并将其添加到 jar 或在 1.7 中重新编译 jar 并确保您 运行 所在的环境具有 1.7 或更高版本。

NoClassDefFoundError 指出 class 在运行时不可用。确保你在 class 路径中有它或者静态初始化程序(如果存在)没有中断。对于后者,您将在堆栈跟踪的下方某处看到 ExceptionInInitializerError。

不太确定 jdk 版本是否重要。

I am getting noclassdeffounderror after deploying the jar with changes to a certain class file.

这是因为存在您的代码所依赖的 class 文件,并且它在编译时存在但在运行时未找到 (see this answer)。

While deploying i Just dragged the .class file from the eclipse work space into a pre existing jar file. does that matter?

是的,这很重要。请务必将 class 文件放回正确的包文件夹中。例如,包 com.foo 中的 class 必须位于 jar 文件内的文件夹 com/foo 中。当您将更改后的版本拖到 jar 文件中时,您更改后的版本可能会出现在其他地方。

Does the jdk version in which the jar file is compiled matter because i am running on jre 1.7 in eclipse but my deployment environment is of jre 1.6 ?

jar 文件本身只是一个 zip 文件,所以不,使用哪个版本的 Java 来压缩 jar 文件的内容并不重要。

但是,如果您从现有的 jar 文件重新编译了一个 class,确实 使用了哪个版本的 Java编译 jar 文件中的其他 classes,因为您可能导致 class 与其同伴 classes 不兼容。

当我编译 jdk 1.6 中的代码时,这非常有效。 java.security.SecureClassLoader 在两个版本中都发生了变化。这就是为什么我想我得到了错误。