When programming in Java, you make other classes available to the class you are writing by putting something like this at the top of your source file:

import org.javaguy.coolframework.MyClass;

Or sometimes you 'bulk import' stuff by saying:

import org.javaguy.coolframework.*;

So later in your program when you say:

MyClass mine = new MyClass();

The Java Virtual Machine will know where to find your compiled class.

It would be impractical to have the VM look through every folder on your machine, so you have to provide the VM a list of places to look. This is done by putting folder and jar files on your classpath.

Before we talk about how the classpath is set, let's talk about .class files, packages, and .jar files.

First, let's suppose that MyClass is something you built as part of your project, and it is in a directory in your project called output. The .class file would be at output/org/javaguy/coolframework/MyClass.class (along with every other file in that package). In order to get to that file, your path would simply need to contain the folder 'output', not the whole package structure, since your import statement provides all that information to the VM.

Now let's suppose that you bundle CoolFramework up into a .jar file, and put that CoolFramework.jar into a lib directory in your project. You would now need to put lib/CoolFramework.jar into your classpath. The VM will look inside the jar file for the org/javaguy/coolframework part, and find your class.

So, classpaths contain:

  • JAR files, and
  • Paths to the top of package hierarchies.

How do you set your classpath?

The first way everyone seems to learn is with environment variables. On a unix machine, you can say something like:

export CLASSPATH=/home/myaccount/myproject/lib/CoolFramework.jar:/home/myaccount/myproject/output/

On a Windows machine you have to go to your environment settings and either add or modify the value that is already there.

The second way is to use the -cp parameter when starting Java, like this:

java -cp "/home/myaccount/myproject/lib/CoolFramework.jar:/home/myaccount/myproject/output/"  MyMainClass

A variant of this is the third way which is often done with a .sh or .bat file that calculates the classpath and passes it to Java via the -cp parameter.

There is a "gotcha" with all of the above. On most systems (Linux, Mac OS, UNIX, etc) the colon character (:) is the classpath separator. On Windows the separator is the semicolon (;)

So what's the best way to do it?

Setting stuff globally via environment variables is bad, generally for the same kinds of reasons that global variables are bad. You change the CLASSPATH environment variable so one program works, and you end up breaking another program.

The -cp is the way to go. I generally make sure my CLASSPATH environment variable is an empty string where I develop, whenever possible, so that I avoid global classpath issues (some tools aren't happy when the global classpath is empty though - I know of two common, mega-thousand dollar licensed J2EE and Java servers that have this kind of issue with their command-line tools).

Answer from bokmann on Stack Overflow
Top answer
1 of 12
910

When programming in Java, you make other classes available to the class you are writing by putting something like this at the top of your source file:

import org.javaguy.coolframework.MyClass;

Or sometimes you 'bulk import' stuff by saying:

import org.javaguy.coolframework.*;

So later in your program when you say:

MyClass mine = new MyClass();

The Java Virtual Machine will know where to find your compiled class.

It would be impractical to have the VM look through every folder on your machine, so you have to provide the VM a list of places to look. This is done by putting folder and jar files on your classpath.

Before we talk about how the classpath is set, let's talk about .class files, packages, and .jar files.

First, let's suppose that MyClass is something you built as part of your project, and it is in a directory in your project called output. The .class file would be at output/org/javaguy/coolframework/MyClass.class (along with every other file in that package). In order to get to that file, your path would simply need to contain the folder 'output', not the whole package structure, since your import statement provides all that information to the VM.

Now let's suppose that you bundle CoolFramework up into a .jar file, and put that CoolFramework.jar into a lib directory in your project. You would now need to put lib/CoolFramework.jar into your classpath. The VM will look inside the jar file for the org/javaguy/coolframework part, and find your class.

So, classpaths contain:

  • JAR files, and
  • Paths to the top of package hierarchies.

How do you set your classpath?

The first way everyone seems to learn is with environment variables. On a unix machine, you can say something like:

export CLASSPATH=/home/myaccount/myproject/lib/CoolFramework.jar:/home/myaccount/myproject/output/

On a Windows machine you have to go to your environment settings and either add or modify the value that is already there.

The second way is to use the -cp parameter when starting Java, like this:

java -cp "/home/myaccount/myproject/lib/CoolFramework.jar:/home/myaccount/myproject/output/"  MyMainClass

A variant of this is the third way which is often done with a .sh or .bat file that calculates the classpath and passes it to Java via the -cp parameter.

There is a "gotcha" with all of the above. On most systems (Linux, Mac OS, UNIX, etc) the colon character (:) is the classpath separator. On Windows the separator is the semicolon (;)

So what's the best way to do it?

Setting stuff globally via environment variables is bad, generally for the same kinds of reasons that global variables are bad. You change the CLASSPATH environment variable so one program works, and you end up breaking another program.

The -cp is the way to go. I generally make sure my CLASSPATH environment variable is an empty string where I develop, whenever possible, so that I avoid global classpath issues (some tools aren't happy when the global classpath is empty though - I know of two common, mega-thousand dollar licensed J2EE and Java servers that have this kind of issue with their command-line tools).

2 of 12
127

Think of it as Java's answer to the PATH environment variable - OSes search for EXEs on the PATH, Java searches for classes and packages on the classpath.

🌐
Medium
medium.com › javarevisited › back-to-the-basics-of-java-part-1-classpath-47cf3f834ff
Tutorial on how Java classpath works | Javarevisited
May 15, 2022 - The classpath is simply a list of directories, JAR files, and ZIP archives to search for class files [1]. The runtime needs to know where to find your compiled classes so that’s what you’re providing here.
Discussions

Trying to understand classpath file
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
9
2
March 29, 2024
What exactly is the classpath? I don't fully get it and only know that it's akin to the PATH variable in Linux.
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnjava
5
11
September 6, 2023
java - What's in an Eclipse .classpath/.project file? - Stack Overflow
We recently had an issue with an Eclipse project for one of our team members. Tomcat was not deploying JARs of the application. We eventually noticed the .classpath Eclipse file was not the same as for the team members where the project was OK. More on stackoverflow.com
🌐 stackoverflow.com
.classpath file in Java related to Java or Eclipse - Stack Overflow
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 More on stackoverflow.com
🌐 stackoverflow.com
December 16, 2014

When programming in Java, you make other classes available to the class you are writing by putting something like this at the top of your source file:

import org.javaguy.coolframework.MyClass;

Or sometimes you 'bulk import' stuff by saying:

import org.javaguy.coolframework.*;

So later in your program when you say:

MyClass mine = new MyClass();

The Java Virtual Machine will know where to find your compiled class.

It would be impractical to have the VM look through every folder on your machine, so you have to provide the VM a list of places to look. This is done by putting folder and jar files on your classpath.

Before we talk about how the classpath is set, let's talk about .class files, packages, and .jar files.

First, let's suppose that MyClass is something you built as part of your project, and it is in a directory in your project called output. The .class file would be at output/org/javaguy/coolframework/MyClass.class (along with every other file in that package). In order to get to that file, your path would simply need to contain the folder 'output', not the whole package structure, since your import statement provides all that information to the VM.

Now let's suppose that you bundle CoolFramework up into a .jar file, and put that CoolFramework.jar into a lib directory in your project. You would now need to put lib/CoolFramework.jar into your classpath. The VM will look inside the jar file for the org/javaguy/coolframework part, and find your class.

So, classpaths contain:

  • JAR files, and
  • Paths to the top of package hierarchies.

How do you set your classpath?

The first way everyone seems to learn is with environment variables. On a unix machine, you can say something like:

export CLASSPATH=/home/myaccount/myproject/lib/CoolFramework.jar:/home/myaccount/myproject/output/

On a Windows machine you have to go to your environment settings and either add or modify the value that is already there.

The second way is to use the -cp parameter when starting Java, like this:

java -cp "/home/myaccount/myproject/lib/CoolFramework.jar:/home/myaccount/myproject/output/"  MyMainClass

A variant of this is the third way which is often done with a .sh or .bat file that calculates the classpath and passes it to Java via the -cp parameter.

There is a "gotcha" with all of the above. On most systems (Linux, Mac OS, UNIX, etc) the colon character (:) is the classpath separator. On Windows the separator is the semicolon (;)

So what's the best way to do it?

Setting stuff globally via environment variables is bad, generally for the same kinds of reasons that global variables are bad. You change the CLASSPATH environment variable so one program works, and you end up breaking another program.

The -cp is the way to go. I generally make sure my CLASSPATH environment variable is an empty string where I develop, whenever possible, so that I avoid global classpath issues (some tools aren't happy when the global classpath is empty though - I know of two common, mega-thousand dollar licensed J2EE and Java servers that have this kind of issue with their command-line tools).

Answer from bokmann on Stack Overflow
People also ask

What is the purpose of setting a classpath in Java?
The main purpose of setting a classpath is to inform the Java compiler and JVM where to find the necessary class files for a program to function correctly. If a program depends on external libraries or custom classes, classpath acts as a roadmap, ensuring all dependencies are accessible during compilation and runtime. Properly configured classpath prevents runtime errors caused by missing or incorrectly referenced resources.
🌐
lenovo.com
lenovo.com › home
Java Classpath: Definition, Usage, Options & Best Practices | Lenovo ...
Can classpath include multiple directories or JAR files?
Yes, classpath can include multiple directories or JAR files. It allows Java programs to locate classes scattered across different locations. Entries are separated by a semicolon (;) on Windows or a colon (:) on Unix-based systems. This flexibility is useful when projects rely on libraries stored in various directories or external JAR files. Developers can list all required paths within the classpath to ensure smooth execution and compilation.
🌐
lenovo.com
lenovo.com › home
Java Classpath: Definition, Usage, Options & Best Practices | Lenovo ...
When would I use a relative path in the classpath?
A relative path is useful when a project’s structure is consistent across different environments, such as collaborative teams using shared repositories. By referencing class files or libraries relative to the project directory, you avoid hardcoding absolute paths, making the project more portable and easier to share. This approach is also advantageous in build environments like CI/CD pipelines.
🌐
lenovo.com
lenovo.com › home
Java Classpath: Definition, Usage, Options & Best Practices | Lenovo ...
🌐
Wikipedia
en.wikipedia.org › wiki › Classpath
Classpath - Wikipedia
May 30, 2026 - 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 the class is first used). The classpath tells Java where to look in the filesystem for files defining these classes.
🌐
Oracle
docs.oracle.com › javase › › 7 › docs › technotes › tools › windows › classpath.html
Setting the class path
The class path is the path that the Java runtime environment searches for classes and other resource files. The class search path (more commonly known by the shorter name, "class path") can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting ...
🌐
Reddit
reddit.com › r/javahelp › trying to understand classpath file
r/javahelp on Reddit: Trying to understand classpath file
March 29, 2024 -

I just started learning Java so we have a study group where we are supposed to create a simple desktop application using Eclipse IDE and WindowBuilder.

I created the base project and then proceeded to push it to the shared repository. The rest of the people in the team tried executing the base project without success, while I could run it without any issues.

After a while, one of the members realized there is a problem with the classpatch file:

<?xml version="1.0" encoding="UTF-8"?>

<classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE\_CONTAINER"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/com.ibm.icu\_74.2.0.jar" sourcepath="/snap/eclipse/85/plugins/com.ibm.icu\_74.2.0.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/jakarta.annotation-api\_2.1.1.jar" sourcepath="/snap/eclipse/85/plugins/jakarta.annotation-api\_2.1.1.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.core.commands\_3.12.0.v20240214-1640.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.core.commands\_3.12.0.v20240214-1640.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.core.runtime\_3.31.0.v20240215-1631.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.core.runtime\_3.31.0.v20240215-1631.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.e4.ui.di\_1.5.300.v20240116-1723.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.e4.ui.di\_1.5.300.v20240116-1723.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.equinox.common\_3.19.0.v20240214-0846.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.equinox.common\_3.19.0.v20240214-0846.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.equinox.registry\_3.12.0.v20240213-1057.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.equinox.registry\_3.12.0.v20240213-1057.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.jface\_3.33.0.v20240214-1640.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.jface\_3.33.0.v20240214-1640.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.jface.text\_3.25.0.v20240207-1054.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.jface.text\_3.25.0.v20240207-1054.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.osgi\_3.19.0.v20240213-1246.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.osgi\_3.19.0.v20240213-1246.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.swt.gtk.linux.x86\_64\_3.125.0.v20240227-1638.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.swt.gtk.linux.x86\_64\_3.125.0.v20240227-1638.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.text\_3.14.0.v20240207-1054.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.text\_3.14.0.v20240207-1054.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.ui.forms\_3.13.200.v20240108-1539.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.ui.forms\_3.13.200.v20240108-1539.jar"/> <classpathentry kind="lib" path="/snap/eclipse/85/plugins/org.eclipse.ui.workbench\_3.131.100.v20240221-2107.jar" sourcepath="/snap/eclipse/85/plugins/org.eclipse.ui.workbench\_3.131.100.v20240221-2107.jar"/> <classpathentry kind="output" path="bin"/> </classpath>

This is making reference to several libs which exist only in my notebok, where I am using Ubuntu. They are trying to run it in Windows.

Is it not kind of stupid to refer to these libs this way? I am still trying to understanc why Java would make reference to these libs assuming all of us would be using Ubuntu? Nobody else in my team has the snap folder :/

Could you please help me understand what is going on? How can we fix it?

I tried looking for some videos explaining the classpath file but no luck so far.

Thank you :(

Top answer
1 of 4
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2 of 4
1
The Eclipse .classpath and .project files as you have found out have absolute file system refs pointing to dependent jars, plugins and other resources that only work on your machine, unless all your team mates have PCs set up with identical filesystem layouts and files in expected locations … highly unlikely. For this reason .classpath, .project, .settings are usually ignored from your git commits and not shared with others. As an alternative, use a Maven pom.xml file to describe your 3rd party dependencies. Each other dev can import the project as a Maven project into Eclipse and it will download deps and set your classpath. Gradle is another alternative.
🌐
Medium
medium.com › @rostyslav.ivankiv › what-is-java-classpath-what-every-developer-should-know-e5f648bde862
What is Java Classpath? What every developer should know | by Rostyslav Ivankiv | Medium
March 5, 2023 - To simplify, the Java Classpath is just a collection of paths (directories and JAR files) used by the Java Compiler to compile and by Java Virtual Machine (JVM) to look for classes or other resources that are required by a Java program at runtime.
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › core java › understanding java’s classpath vs. build path
Understanding Java’s Classpath vs. Build Path | Baeldung
August 28, 2024 - The classpath is an environment variable used by the Java Virtual Machine (JVM) to locate and load classes when running a Java program. It specifies a list of directories, JAR files, and ZIP files where the JVM should look to find and load class ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › tools › windows › classpath.html
2 Setting the Class Path
April 21, 2026 - The class path is the path that the Java Runtime Environment (JRE) searches for classes and other resource files. ... The class search path (class path) can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable.
🌐
DEV Community
dev.to › martingaston › understanding-the-java-classpath-building-a-project-manually-3c3l
Understanding the Java Classpath: Building a Project Manually - DEV Community
July 27, 2019 - Which is just charming. Essentially, our classpath needs to contain the path to our .jar files to the top of our package hierarchies.
🌐
Lenovo
lenovo.com › home
Java Classpath: Definition, Usage, Options & Best Practices | Lenovo US
Classpath is a parameter used by the Java compiler and JVM (Java Virtual Machine) to determine the location of class files required for compiling and running Java applications. It can point to directories, JAR files, or other resources containing bytecode. Classpath ensures the program can ...
🌐
Reddit
reddit.com › r/learnjava › what exactly is the classpath? i don't fully get it and only know that it's akin to the path variable in linux.
r/learnjava on Reddit: What exactly is the classpath? I don't fully get it and only know that it's akin to the PATH variable in Linux.
September 6, 2023 -

I read this:

In Java, the term "classpath" refers to a parameter that specifies a set of directories or JAR (Java Archive) files where the Java Virtual Machine (JVM) and Java compiler should look for classes and resources when running or compiling Java applications

But where does this classpath comes into existence? If you for example have a completely vanilla project with some source code, and want to compile it manually with javac, does this notion of class path exist, for example?

How does it work in the context of build automation tools like Maven?And in an intelliJ project, for example, where can I find the class path and how does it work relatively to the project?

I've read a lot about what it does, but not what it exactly is and I would really appreciate some clarification!

Edit: I tried to look at the docs (oracle for example), but even there it's all kind of vague.

Top answer
1 of 3
3
Check out the answers in here : https://stackoverflow.com/questions/2396493/what-is-a-classpath-and-how-do-i-set-it
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
Top answer
1 of 3
167

Eclipse is a runtime environment for plugins. Virtually everything you see in Eclipse is the result of plugins installed on Eclipse, rather than Eclipse itself.

The .project file is maintained by the core Eclipse platform, and its goal is to describe the project from a generic, plugin-independent Eclipse view. What's the project's name? what other projects in the workspace does it refer to? What are the builders that are used in order to build the project? (remember, the concept of "build" doesn't pertain specifically to Java projects, but also to other types of projects)

The .classpath file is maintained by Eclipse's JDT feature (feature = set of plugins). 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).

Blindly copying such files from one machine to another may be risky. For example, if arbitrary JAR files are placed on the classpath (that is, JAR files that are located outside the workspace and are referred-to by absolute path naming), the .classpath file is rendered non-portable and must be modified in order to be portable. There are certain best practices that can be followed to guarantee .classpath file portability.

2 of 3
12

Complete reference is not available for the mentioned files, as they are extensible by various plug-ins.

Basically, .project files store project-settings, such as builder and project nature settings, while .classpath files define the classpath to use during running. The classpath files contains src and target entries that correspond with folders in the project; the con entries are used to describe some kind of "virtual" entries, such as the JVM libs or in case of eclipse plug-ins dependencies (normal Java project dependencies are displayed differently, using a special src entry).

🌐
Computer Hope
computerhope.com › jargon › c › classpath.htm
What Is a Classpath?
Classpath is a parameter that tells the Java compiler, or the JVM (Java Virtual Machine), where to find class files to import.
🌐
Study.com
study.com › business courses › java programming tutorial & training
What is Classpath in Java? - Definition & Example - Lesson | Study.com
March 20, 2019 - An environment variable is a global ... and USERNAME. In Java, CLASSPATH holds the list of Java class file directories and the JAR file, which is Java's delivered class library file....
🌐
Quora
quora.com › What-is-classpath-in-a-project-Why-do-I-need-to-include-libraries-and-jars-in-my-classpath-when-I-build-it
What is classpath in a project? Why do I need to include libraries and jars in my classpath when I build it? - Quora
Classpath in a project is the list of locations the Java runtime and compiler search for compiled classes and resources (*.class files, resource bundles, META-INF, etc.) when running or building an application.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › paths.html
PATH and CLASSPATH (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
Setting the CLASSPATH can be tricky and should be performed with care. The default value of the class path is ".", meaning that only the current directory is searched.
🌐
O'Reilly
oreilly.com › library › view › learning-java-4th › 9781449372477 › ch03s04.html
The Classpath - Learning Java, 4th Edition [Book]
June 25, 2013 - In a Unix shell, the PATH environment ... command. The Java CLASSPATH environment variable, similarly, is a list of locations that are searched for Java class files....
Authors   Patrick NiemeyerDaniel Leuck
Published   2013
Pages   1007
🌐
Codemia
codemia.io › home › knowledge hub › what is a classpath and how do i set it?
What is a classpath and how do I set it? | Codemia
January 26, 2025 - The classpath is crucial for Java applications, as it informs the Java Virtual Machine (JVM) where to find user-defined and third-party classes. The classpath can include the input for directories, JAR files (Java ARchive - a package file format typically used to aggregate many Java class files and associated metadata and resources), and ZIP files where Java classes and resources are located.
🌐
Reddit
reddit.com › r/learnprogramming › understanding java classpath.
r/learnprogramming on Reddit: Understanding Java classpath.
January 13, 2021 -

I was surfing stackoverflow, trying to better understand what the classpath is all about and came upon this question/answer. It mostly makes sense, but there are two slightly confusing paragraphs in the accepted answer that go:

First, let's suppose that MyClass is something you built as part of your project, and it is in a directory in your project called output. The .class file would be at output/org/javaguy/coolframework/MyClass.class (along with every other file in that package). In order to get to that file, your path would simply need to contain the folder 'output', not the whole package structure, since your import statement provides all that information to the VM.

Now let's suppose that you bundle CoolFramework up into a .jar file, and put that CoolFramework.jar into a lib directory in your project. You would now need to put lib/CoolFramework.jar into your classpath. The VM will look inside the jar file for the org/javaguy/coolframework part, and find your class.

I don't understand the two sentences that say:

You would now need to put lib/CoolFramework.jar into your classpath. The VM will look inside the jar file for the org/javaguy/coolframework part, and find your class.

Why would the VM "look inside the jar file for the org/javaguy/coolframework part"? Why does that structure exist within the jar file? The answer mentions that you bundle "CoolFramework up into a .jar file", so why would that include the org/javaguy/coolframework hierarchy? Isn't CoolFrameWork just a single directory?