简体   繁体   中英

ClassNotFoundException for JUnit tests in AspectJ project in Eclipse

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)

Previously I faced similar issue and problem was because of broken build paths to external libraries (eg 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM