0

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?

MIT
  • 109
  • 1
  • 7
  • Possible duplicate of [What is the difference between Class Path and Build Path](http://stackoverflow.com/questions/3529459/what-is-the-difference-between-class-path-and-build-path) – Reenactor Rob Nov 28 '16 at 07:31

1 Answers1

2

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.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199
  • Thank you for answering my question, Mr. Karr. If I add a jar: ABC to the project build path.....Does it mean it will be included automatically when I run/debug the project? Or I need to do it manually (under eclipse env). Also could you please give me an example, when the lib will only be needed for run/debug configuration but not the build path. – MIT Nov 29 '16 at 08:58
  • 1
    Again, the resources in the buildpath are automatically used in the run configuration for a class in the project. Concerning indirect references, this is done with Reflection. Look up "java reflection". – David M. Karr Nov 29 '16 at 18:45