Fading Coder

An Old Coder’s Final Dance

Home > Tech > Content

Understanding the Eclipse .classpath File

Tech 1

Overview

In Eclipse-based Java projects, the .classpath file describes the project’s build path. Eclipse uses it to locate source roots, decide where to write compiled .class files, discover JRE and server runtimes, and resolve external libraries and project dependencies. If this file is missing or corrupted, Eclipse can no longer treat the folder as a Java project and many Java tooling features will not work.

What .classpath Records

The file is an XML document containing entries that define:

  • Source folders
  • The output directory for compiled classes
  • JRE and other runtime containers (for example, a server runtime)
  • Referenced JARs and user libraries
  • Project dependencies and access rules

All changes made through Project > Properties > Java Build Path are persisted to .classpath.

A Minimal Example

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="src" path="src"/>
  <classpathentry kind="src" path="resources"/>

  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
    <attributes>
      <attribute name="owner.project.facets" value="java"/>
    </attributes>
  </classpathentry>

  <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Tomcat 9.0"/>
  <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
  <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>

  <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath>

Root element is . Each line describes one build-path entry. The kind attribute specifies the entry type, and path gives its location. Paths are generally relative to the project directory that contains .classpath.

Entry Types

kind="src" — Source Folders

A source folder contributes Java sources to the build path.

<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
  • path is relative to the project root.
  • Adding or removing source folders via Java Build Path > Source updates these entries.

Referencing a source folder from another project in the same workspace uses a leading slash and can optionally include access rule behavior:

<classpathentry kind="src" path="/common-utils" combineaccessrules="false"/>

The path "/common-utils" points to a sibling project named common-utils.

kind="output" — Compiled Class Destination

Defines where Eclipse writes .class files produced from source folders.

<classpathentry kind="output" path="WebContent/WEB-INF/classes"/>

Changing the output location in the project’s build path settings updates this entry. For example:

<classpathentry kind="output" path="WebContent/WEB-INF/build-classes"/>

kind="con" — Classpath Containers

A container contributes a logical group of entries managed by Eclipse or a plug-in (for example, the JRE, a server runtime, or user-defined libraries).

JRE Container

Different selection modes determine the path value:

  • Workspace default JRE:
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    
  • A specific installed JRE:
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-17"/>
    
  • An execution enviroment:
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    

Some tools add attributes to express facets or usage context:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
  <attributes>
    <attribute name="owner.project.facets" value="java"/>
  </attributes>
</classpathentry>

Server Runtime Container

Used by Dynamic Web Projects to add a server’s libraries to the build path.

<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Tomcat 9.0"/>

Web App Libraries Container

Aggregates libraries under WEB-INF/lib and other web-app scoped entries.

<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>

J2EE Module Dependencies

Internal container for J2EE module linkage with in the workspace.

<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>

User Libraries

A user-defined logical library registered in Eclipse (Preferences > Java > Build Path > User Libraries).

<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/logging-stack"/>

kind="lib" — Referenced JARs

Direct references to external JAR files.

<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-dbcp-1.2.1.jar"/>

Adding or removing JARs via Java Build Path > Libraries updates these entries.

Build Path Order and Resolution

The order of elements affects class resolution. Eclipse uses the order shown in Java Build Path > Order and Export and persists it too .classpath. Typical practice is to list source folders first, followed by containers (JRE, server), then libraries. If classes with the same name appear in multiple locations, the first matching entry in this order wins.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.