-5

I have read many sites and then decided to ask this question on stackoverflow, question is pretty basic

What is .classpath file? Is this file related to the Java project or Eclipse?

Some people think that this file related to Eclipse and some thinks that it is related to project?

atish shimpi
  • 4,873
  • 2
  • 32
  • 50

6 Answers6

4

.class files are related to Java.

You write your code in java, it is compiled by javac into bytecode. The bytecode is stored in the .class files, and further interpreted by the Java virtual machine (JVM).


About .classpath on Wikipedia:

Similar to the classic dynamic loading behavior, when executing Java programs, the Java Virtual Machine finds and loads classes lazily (it loads the bytecode of a class only when this class is first used). The .classpath tells Java where to look in the file-system for files defining these classes.

So the .classpath mechanism is related to Java, and is handled by eclipse thanks to the .classpath file.

Hope it helps :)

Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58
NiziL
  • 5,068
  • 23
  • 33
  • I have edited my question, I tried to ask you about `.classpath` file? – atish shimpi Dec 16 '14 at 13:23
  • is `classpath` file part of repository? if not then how can the classpath tells Java where to look in the filesystem for files defining these classes. – atish shimpi Dec 17 '14 at 05:57
  • @atishshimpi There is a debate about add `.classpath` and `.project` files in the VCS, see [this question](http://stackoverflow.com/questions/3611728/java-project-should-classpath-project-file-be-committed-into-repository) and [this one](http://stackoverflow.com/questions/2818239/classpath-and-project-check-into-version-control-or-not) – NiziL Dec 17 '14 at 16:07
2

It's java bytecode in .class file. Whenever you compile the javacode, you will get .class file per java class. Behind the scenes, Eclipse incrementally does compile your java code in the project and hence you don't end up manually compiling our java code.

SMA
  • 36,381
  • 8
  • 49
  • 73
2

The .classpath file is Eclipse's way to keep track of a project's classpath and other build related settings. If you right click on your project and go to Java Build Path, those are the things that are saved in the .classpath file.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
1

The .classpath file is maintained by Eclipse's JDT . JDT holds multiple such "meta" files in the project (see the .settings directory inside the project); the .classpath file is just one of them. Specifically, the .classpath file contains information that the JDT feature needs in order to properly compile the project: the project's source folders (that is, what to compile); the output folders (where to compile to); and classpath entries (such as other projects in the workspace, arbitrary JAR files on the file system, and so forth).

Nikhil Kumar K
  • 1,089
  • 10
  • 13
0

From the wiki

Java class file is a file (with the .class filename extension) containing a Java bytecode which can be executed on the Java Virtual Machine (JVM). 
Java class file is produced by Java compiler from Java programming language source files (.java files) containing Java classes. 
If a source file has more than one class, each class is compiled into a separate class file.
MihaiC
  • 1,618
  • 1
  • 10
  • 14
0

I can say .classpath is a file required/related only if you are running java project in the eclipse.

Explanation:

You may need some jar file required to run your project, so in this case you have to include these jars in your classpath in order to run your project/application. If you are running manually you have to include jars to classpath and then execute, but if you are using Eclipse this classpath information i.e. the jars that needs to be added will be there in the .classpath file so that you need not add jars manually to the classpath.

NOTE: .classpath file will be automatically generated by the eclipse, this will have the information of the jars you added in you eclipse build path.

Shri
  • 469
  • 5
  • 18