0

I will do my best to explain the exact situation we ran into. Let me know if you guys have additional questions. I do not know if this is a java linking issue or a java loading issue.

I have compiled the code using a external jar file which has changed during the execution. I am referencing a class file called "Contract" in my code. The library which I am using at compile time has a "Contract" class which extends from the "BaseContract" class. But the library which I am using at execution time does not have a super class ("BaseContract"). At runtime, I get a a error saying BaseContract class is not found. The class referencing the "Contract" class, lets say, is called "AppClass".

At compile time, does java store the class hierarchy of all its referenced classes in the class file which is being compiled. In my specific example, does java store the class hierarchy of the "Contract" class in the AppClass.class file? If so, why does java have to store the class hierarchy here. Is it not more efficient to store the class "Contract" hierarchy in the Contract.class file rather than in the AppClass.class file?

Any help or pointers are greatly appreciated.

7
  • The classloader will need access to all relevant classes at runtime. Please put all relevant jars in the classpath at startup. Basically any class you are going to at runtime must be defined and in the classpath at startup Commented Jan 13, 2014 at 19:30
  • Do you have any imports for BaseContract in you code? Commented Jan 13, 2014 at 19:31
  • Did you make sure to 'package' all of your classes? Do any of your classes import BaseContract? Commented Jan 13, 2014 at 19:31
  • @Robert Beltran : The jar file which contains the "Contract" class file is already in the classpath, but the Contract classfile which is in the classpath does not extend from the "BaseContract" class. Commented Jan 13, 2014 at 19:34
  • 1
    I'm confused. Maybe we could get some code to look at? Commented Jan 13, 2014 at 19:37

1 Answer 1

1

No, it doesn't. Each class knows only it's own class hierarchy. However it also knows when it goes to make a method call, create an object, etc the expected signature of that method, type of that object, etc.

If nothing is available matching that expectation then you will get the class not found error (or other similar errors depending on exactly what the miss-match is).

Sign up to request clarification or add additional context in comments.

3 Comments

When you say, "However it also knows when it goes to make a method call, create an object, etc the expected signature of that method, type of that object, etc", this is only at execution time, right?
Also, I de-compiled the AppClass.class file and it does not have references to the BaseContract class.
At the point you compile then it needs access to the library in order to do the compilation (i.e. check that it is calling the right methods etc). Once the compilation is done it can run without the other class - but as soon as it tries to make a call or reference to anything in that class then if the class loader cannot find it you will get an exception thrown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.