I am having problems importing an external .class file into an eclipse project. I have read through most of the related questions and none of those answer have worked for me. Here is the following code for my project:
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import timing.Timing;
public class Test {
public static void main(String[] args){
int seed = 518406;
long begin = 0;
long end = 0;
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
for(int i = 1; i < 10000; i=i*2){
begin = bean.getCurrentThreadCpuTime();
Timing.trial(i, seed);
end = bean.getCurrentThreadCpuTime();
System.out.println(i + ": " + (end - begin) + "ns");
}
}
}
I have imported by placing the Timing.class file in at /lib/timing/Timing.class and I have added the lib folder as a Class Folder to the build path. In the Order and Export tab of the build path window, I have moved the lib folder to the top and have it checked.
When running the code above I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: Timing
at Test.main(Test.java:14)
Caused by: java.lang.ClassNotFoundException: Timing
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
Can anybody help me figure out what is going wrong?
In stacktrace this line looks strange
Exception in thread “main” java.lang.NoClassDefFoundError: Timing
It seems like java search
Timingin default package not intimingpackage. Check this moment.2 How do you run this code? From Eclipse?
If so, check Eclipse run configuration for this launch. May be you add class folder to Build path but don’t add it launch class path.