无法解决 java NoClassDefFoundError 但一切看起来都正确......有什么想法吗?
如果我没有提供足够的信息或者我不清楚任何事情,请提前抱歉,这是我第一次尝试使用 .bat
和 .config
文件。
我正在使用一款学术软件,并尝试添加和运行我自己的组件。系统使用配置文件来启动系统所需的组件(类)列表,使用如下代码:
semaine.components = \
eu.semaine.examples.swimmer.SwimmerDisplay| \
系统正确运行并且指定的组件被初始化。
我使用以下代码将自己的组件添加到现有组件列表中:
eu.semaine.examples.TestPackage.MyTest| \
但是出现以下错误:
java.lang.NoClassDefFoundError:eu/semaine/examples/TestPackage/MyTest(错误名称:TestPackage/MyTest)
我环顾四周,在我看来,我没有做任何通常会导致此错误的事情,例如我的类名与其存储的文件名匹配(公共类MyTest
存储在MyTest.java
中),MyTest
位于package TestPackage
并且文件结构中的文件夹也被命名为TestPackage
。
任何想法或建议将不胜感激。
sorry in advance if I don't give enough information or if I'm unclear about anything, this is my first foray into using .bat
and .config
files.
I'm using a piece of academic software and am trying to add and run my own components. the system uses a config file to launch a list of components (classes) required for the system using code like this:
semaine.components = \
eu.semaine.examples.swimmer.SwimmerDisplay| \
the system runs correctly and the specified components are initialised.
I add my own component to the list of existing components using the following code:
eu.semaine.examples.TestPackage.MyTest| \
however I get the following error:
java.lang.NoClassDefFoundError:eu/semaine/examples/TestPackage/MyTest (wrong name: TestPackage/MyTest)
I've had a look around and it seems to me that I'm not doing any of the things which usually cause this error, e.g. my class name matches the file name it is stored in (public class MyTest
is stored in MyTest.java
), MyTest
is in the package TestPackage
and the folder in the file structure is also named TestPackage
.
any ideas or advice would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您已要求
但说您已将该文件放置在名为 TestPackage 的目录中。
仔细查看批处理文件中指定的类路径。我的猜测是,对于初始冲突,您有一个像这样的目录层次结构,植根于指定的类路径,
在说 eu.semaine.examples.TestPackage.MyTest 您说该包将是“eu.semaine.examples.TestPackage”并且目录层次结构现在将是
我认为你打算改为:
并说该类不是
[
顺便说一句,我同意正常约定不是将包名称大写,但我不相信 Java 从大写推断和语义.]
You have asked for
but say that you have placed the file in a directory called TestPackage.
Look carefully at the classpath specified in your batch file. My guess is that you have a directory hierarchy like this for the initial clash, rooted at that specified classpath
in saying eu.semaine.examples.TestPackage.MyTest you are saying that the package will be "eu.semaine.examples.TestPackage" and the directory hierarchy will now be
I think you intend instead:
and to say that the class is just
not
[In passing I agree that normal convention is not to capitalise package names, but I don't beleive that Java infers and semantic from the capitalisation.]
听起来您的类在应用程序启动时不在其类路径中。您提到了 .bat 文件。如果这就是您启动应用程序的方式,那么它应该包含一个组装类路径的部分。它必须包含
TestPackage
文件夹的父文件夹,以便 JVM 知道在哪里可以找到您的类文件。It sounds like your class is not in the application's classpath when it's started. You mention
.bat
files. If that's how you start the application, then it should contain a section where the classpath is assembled. It must contain the parent folder of theTestPackage
folder so that the JVM knows where to find your class file.命名约定规定包名称必须全部小写,请参见 http://下载.oracle.com/javase/tutorial/java/package/namingpkgs.html。
我猜jvm认为TestPackage是一个类,而MyTest是一个内部类。
Naming convention states that package names must be all lower case, see http://download.oracle.com/javase/tutorial/java/package/namingpkgs.html.
I guess the jvm thinks that TestPackage is a class and MyTest is an inner class.