I have two different java projects (I’ll call them project 1 and Project 2 for simplicity’s sake) loaded into eclipse, and project 1 is added to the build path of project 2. I have imported the only package in the src folder of project 1 into a test class for project 2, and within the code of that test class I have simple object declarations of classes from project 1 as such:
ProjectOneClass object = new ProjectOneClass();
This code compiles without error, the compiler recognizes that these classes are on the build path. When I run the code as a Java application via Junit4, though, the program throws ClassNotFoundExceptions when it comes across these lines of code. The code is supposed to print these ClassNotFoundExceptions to the error log, but for some reason nothing is being printed. I’m using a simple
try {
...
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
structure, so I don’t know why it’s not printing to the error log.
The JUnit printout is simply:
Junit execution complete
Summary: 4 succeeded, 3 failed.
The four that succeed do not reference the imported project 1 package.
I have tried all manners of changes to the build path configurations, and nothing has shown any promise of improvement. The only thing I can think might be able to fix this is the order of the build path as specified in the Order And Export tab of the build path configuration window. Right now the order is:
project 2 packages
EAR Libraries
JRE System Libraries
JUnit4
a few JAR files (c3p0, commons-codec, ojdbc6)
project 1
I don’t know for sure if the problem lies here or elsewhere, though. If anyone can help me out with this, I’d be very grateful. Thanks for reading.
I figured out the issue. Project 1 relies on several JARs that Project 2 doesn’t have as part of its build path. I figured that since Project 1 had those JARs set within its build path, it would still work fine. Upon creating instances of classes from Project 1, however, I found that Project 2 required these JARs in its own build path.
This would make sense to me if the classes I was instantiating were implementations/extensions of a class from one of these JARs, but they weren’t.
Regardless, by adding a couple of JARs to Project 2 I fixed the problem. Thanks everyone.