Was just looking at Buildpath
and Classpath
for my Java
project in Eclipse
. I noticed all jars included in my project's buildpath are automatically included its classpath.
It makes sense why Eclipse does that. I mean , If I need to instantiate an external class in my code then I need those classes in by buildpath for the code to compile. And at runtime i need those very same classes loaded into the jvm too.
It then looks like all classes included in the buildpath are needed in classpath. Although I cannot think of a case where a project's classpath will be different from its buildpath .
Is the above understanding accurate ? Could you give me a scenario where classpath will have additional classes than those in the buildpath ?
There are many situations where classes are only needed at runtime, not compile time. One of the most typical is JDBC drivers; code is written/compiled against the JDBC API, but at runtime a driver class must be available on the classpath. There are any number of other examples, especially when you get into various frameworks that have a standard API and differing implementations that can be "injected" at runtime.