Eclipse 中 AspectJ 项目中 JUnit 测试的 ClassNotFoundException

发布于 2024-10-05 08:49:51 字数 1310 浏览 0 评论 0原文

Google 对此有一些答案,但它们都是针对使用 Maven 的人的。我没有使用 Maven,所以我很困惑。我还有其他未使用 AspectJ 插件的项目,它们的 JUnit 测试在 Eclipse 中运行良好。我不明白为什么 Eclipse 找不到该类。我右键单击类本身,然后告诉它作为 JUnit 测试运行。它适用于我的非 AspectJ 项目中的 JUnit 测试。有人可以帮忙吗?

Class not found BasicSpectrogramPeriodogramTests
java.lang.ClassNotFoundException: BasicSpectrogramPeriodogramTests
    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:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Google has some answers for this, but they are all for people using Maven. I am not using Maven so I am stumped. I have other projects that are not using the AspectJ plugin and their JUnit tests run fine in Eclipse. I cannot figure out why Eclipse cannot find the class. I right click on the class itself and then I tell it to run as a JUnit test. It works for JUnit tests in my non-AspectJ projects. Can anybody help?

Class not found BasicSpectrogramPeriodogramTests
java.lang.ClassNotFoundException: BasicSpectrogramPeriodogramTests
    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:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

苏佲洛 2024-10-12 08:49:51

以前我遇到过类似的问题,问题是由于外部库(例如 Selenium 服务器)的构建路径损坏所致。因此,首先请打开构建路径(右键单击项目 -> 构建路径 -> 配置构建路径)并验证所有外部库是否可以成功加载(有“无法加载”之类的消息)。最有可能的是,在优化或添加 Ant 等外部工具时,库被重命名/移动。希望这对

WBR、安德烈有帮助

Previously I faced similar issue and problem was because of broken build paths to external libraries (e.g. Selenium server). So first of all please open Build path (right click project -> Build Path -> Configure Build Path) and verify that all external libraries can be loaded successfully (there are messages like 'cannot load'). Most likely a library was renamed/moved while optimization or adding external tools like Ant. Hope this helps

WBR, Andrey

空袭的梦i 2024-10-12 08:49:51

AspectJ 插件可能会影响您的构建类路径,但不会影响运行时类路径。为您的类创建一个启动器条目,然后显式设置类路径以包含该 jar。

使用 Eclipse 的“加载类型”功能来查看它从哪里加载类。

Ctrl-Space-T 会弹出一个对话框。输入目标类名“BasicSpectrogramPeriodogramTests
“。它应该显示工作区中的包名称和位置,要么在所有列出的类的类名右侧,要么在选定类的对话框底部附近。这将包括 jar 及其路径(如果是这样的话) 确保您的类

的路径是运行时配置类路径中的路径,即使它是重复的。

The AspectJ plugin may be influencing your build classpath but not the runtime classpath. Create a launcher entry for your class and then explicitly set the classpath to include the jar.

Use Eclipse's 'load type' function to see where it is loading the class from.

Ctrl-Space-T pulls up a dialog. Enter the target classname, "BasicSpectrogramPeriodogramTests
". It should display the package name and location in the workspace, either to the right of the classname for all listed classes, or near the bottom of the dialog for a selected class. This will include the jar and its path if that is how it is being loaded by Eclipse.

Make sure the path for your class is what is in the runtime config classpath. Add it explicitly at the top of the classpath, even it it is a dup.

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