MIT
MIT

Reputation: 119

Eclipse classpath vs buildpath

I am confused about the Eclipse Run/Debug configurations classpath and build path of java project. I have some ideas about the different of them but not completely sure I am correct. Please correct me if I am wrong or missing anything....

  1. when you right click on a Java project and click on configure build path. it's actually modifying .classpath file of that project....For my understanding, the jar files that lists in this file...are the libraries that needed for compiling the project.
  2. Under Run/Debug Configurations window of Eclipse, there is a Classpath tab. Jar files that under this tab are required for executing the project.

Q1. Am I correct? Any additional information can be added?

Q2. There was once, I have compiled the project and got it started... it was running fine until I used one of the functions, system throws classNotFound exception..later on I added a missing jar to the Buildpath and that function works again. So, I am confused here. If Buildpath is used for compiling the project....that mean I shouldn't able to compile and get the project started at the first place. But it wasn't. Am i missing something here? Why shouldn't I add that missing jar to classpath instead of buildpath?

Upvotes: 0

Views: 1435

Answers (1)

David M. Karr
David M. Karr

Reputation: 15235

Yes, the classes and jars specified in the ".classpath" file are used while compiling the source code of the project, but those same classes and jars are used by default in the run configuration for a class in the project.

Sometimes, there are classes that are required while running a project, but which are not actually needed while compiling the project. There are different reasons for this, but in general it means that the referenced class is not directly referenced in source code, but with indirection through some sort of reflection-based process.

Upvotes: 2

Related Questions