无法解决 java NoClassDefFoundError 但一切看起来都正确......有什么想法吗?

发布于 2024-10-02 01:58:56 字数 755 浏览 0 评论 0原文

如果我没有提供足够的信息或者我不清楚任何事情,请提前抱歉,这是我第一次尝试使用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笔芯 2024-10-09 01:58:56

您已要求

eu.semaine.examples.TestPackage.MyTest

但说您已将该文件放置在名为 TestPackage 的目录中。

仔细查看批处理文件中指定的类路径。我的猜测是,对于初始冲突,您有一个像这样的目录层次结构,植根于指定的类路径,

eu
  semaine
    examples
        swimmer
           SwimmerDisplay

在说 eu.semaine.examples.TestPackage.MyTest 您说该包将是“eu.semaine.examples.TestPackage”并且目录层次结构现在将是

eu
  semaine
    examples
        swimmer
           SwimmerDisplay.class
        TestPackage
           MyTest.class

我认为你打算改为:

eu
  semaine
    examples
        swimmer
           SwimmerDisplay.class
TestPackage
  MyTest.class

并说该类不是

TestPackage.MyTest

[

eu.semaine.examples.TestPackage.MyTest

顺便说一句,我同意正常约定不是将包名称大写,但我不相信 Java 从大写推断和语义.]

You have asked for

eu.semaine.examples.TestPackage.MyTest

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

eu
  semaine
    examples
        swimmer
           SwimmerDisplay

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

eu
  semaine
    examples
        swimmer
           SwimmerDisplay.class
        TestPackage
           MyTest.class

I think you intend instead:

eu
  semaine
    examples
        swimmer
           SwimmerDisplay.class
TestPackage
  MyTest.class

and to say that the class is just

TestPackage.MyTest

not

eu.semaine.examples.TestPackage.MyTest

[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.]

旧伤慢歌 2024-10-09 01:58:56

听起来您的类在应用程序启动时不在其类路径中。您提到了 .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 the TestPackage folder so that the JVM knows where to find your class file.

行至春深 2024-10-09 01:58:56

命名约定规定包名称必须全部小写,请参见 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文