How to Set the Classpath in Eclipse

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
Setup Class path for the project in Eclipse.
Image Credit: Courtesy of Eclipse

In Eclipse, use the Java Build Path to build classpaths in order to compile your work. Eclipse has several options for building paths, including building paths from source folders, libraries and projects.You can also edit your classpaths in order to adapt to ongoing changes in your project.

Advertisement

Step 1

Choose "Build Path."
Image Credit: Courtesy of Eclipse

Right click on the name of the project that you want to build a classpath for in the Package Explorer bar. Click "Build Path" and then choose "Configure Build Path...".

Advertisement

Video of the Day

Step 2

Click "Add Folder..."
Image Credit: Courtesy of Eclipse

Click "Add Folder..." to add the source that you want to build the path from in the Source tab.

Advertisement

Step 3

Choose the folder.
Image Credit: Courtesy of Eclipse

Choose the source folders you need in order to add the path for the source code to the compiler, for example, gen and src. Click "OK." Depending on your project, the source folders you need may vary, but gen and src are basic folders needed for most Java projects. Use source folders to give your project structure. If you don't need specific parts of some source folders, set exclusion filters on them individually. Source folders must not overlap.

Advertisement

Advertisement

Step 4

Choose the project for which you want to build the classpath.
Image Credit: Courtesy of Eclipse

Click "Add..." in the Projects tab if you need to add a path from another project to the compiler. Choose the project and click "OK." This adds classpaths that are marked as exported from the second project to the current project, as well as the source folders for the second project. The second project is added to the current project's referenced projects list. Eclipse builds projects on the referenced projects list first.

Advertisement

Step 5

Click "Add JARs..."
Image Credit: Courtesy of Eclipse

Choose other items to add via the Libraries tab, depending on your project. You can add internal and external JARs, add libraries, and select variables to be used when working in a team, as well as select or create internal and external class folders. As an example, first choose "Add JARs..."

Advertisement

Advertisement

Step 6

Add internal JARs.
Image Credit: Courtesy of Eclipse

Choose the JAR file you need from the projects in the list. Click "OK."

Advertisement

Step 7

Add external JARs.
Image Credit: Courtesy of Eclipse

Click "Add External JARs..." to also include a JAR from another location on your computer if needed for your project. Click "Open" to add the path to the project.

Advertisement

Step 8

Add the JRE library.
Image Credit: Courtesy of Eclipse

Click "Add Library..." to build a path for a library. The exact library you may need varies with your project. For example, to add the Java runtime environment, choose "JRE System Library" and click "Next."

Advertisement

Advertisement

Step 9

Click "Finish."
Image Credit: Courtesy of Eclipse

Click "Finish" to complete setting up the path for the JRE system library. Your classpath is now complete and you can return to your workbench.

Video of the Day

Advertisement

Advertisement

references

Report an Issue

screenshot of the current page

Screenshot loading...