通过切换到另一个项目来实现NoClassDefFoundError [英] NoClassDefFoundError by switching to another project

查看:220
本文介绍了通过切换到另一个项目来实现NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读了很多有关NoClassDefFoundError的答案,但不知何故找不到解决我的问题的答案.也许我没有足够的经验来将其转化为我的问题.

I have read a lot of answers here to NoClassDefFoundError, but somehow I could not find one that solves my problem. Maybe I have not enough experience to transform it to my problem.

无论如何,我有一个项目(通过git导入),它带有一个软件包和许多有用的功能.还有一个带有一些演示的软件包,它们完全可以正常工作.

Anyway, I have a project (imported over git) with a package and lots of helpful functions. There is as well a package with some demos, they work completely fine.

如果我现在在自己的项目中复制这些演示之一,则会收到错误消息

If I now copy one of those demos in my own project, I get the error

线程"main"中的异常java.lang.NoClassDefFoundError:org/jfree/data/xy/XYDataset 在网上.[...]

Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/xy/XYDataset at net.[...]

我认为必须有一个简单的解决方案,因为它可以在另一个项目中运行.

I think there must be a simple solution, since it runs in the other project.

感谢您抽出宝贵的时间.

Thank you for taking your time.

推荐答案

Java虚拟机在运行时无法找到编译时可用的特定类时,就会出现Java中的NoClassDefFoundError.例如,如果我们从类中调用方法或访问类的任何静态成员,而该类在运行时不可用,则JVM将抛出NoClassDefFoundError.

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. For example, if we have a method call from a class or accessing any static member of a Class and that class is not available during run-time then JVM will throw NoClassDefFoundError.

  • 该类在Java Classpath中不可用.
  • 您可能正在使用jar命令运行程序,而该类不是 在清单文件的ClassPath属性中定义.
  • 任何启动脚本都将覆盖Classpath环境变量.
  • 因为NoClassDefFoundError是java.lang.LinkageError的子类 如果它的依赖项之一(例如本机库)可能不可用,它也可能会出现.
  • 如果您在J2EE环境中工作,则Class的可见性除外 多个Classloader之间也可能导致 java.lang.NoClassDefFoundError,有关详细讨论,请参见示例和场景部分.
  • The class is not available in Java Classpath.
  • You might be running your program using jar command and the class was not defined in manifest file's ClassPath attribute.
  • Any start-up script is overriding Classpath environment variable.
  • Because NoClassDefFoundError is a subclass of java.lang.LinkageError it can also come if one of its dependency like native library may not available.
  • If you are working in J2EE environment than the visibility of Class among multiple Classloader can also cause java.lang.NoClassDefFoundError, see examples and scenario section for detailed discussion.

这篇关于通过切换到另一个项目来实现NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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