How to Set the Classpath in 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.
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...".
Click "Add Folder..." to add the source that you want to build the path from in the Source tab.
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.
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.
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..."
Choose the JAR file you need from the projects in the list. Click "OK."
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.
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."
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.
Tips & Warnings
- The steps here don't need to be in sequential order. You can add items from the Source, Projects, and Libraries tabs in any order. When you have finished adding items, return to your workbench.
- As an alternative way to get to the Java Build Path, you can click "Project Properties" in the Context Menu of a created project or the File Menu on the workbench.
- If you accidentally add wrong items to your classpath or forget to add necessary items, Eclipse gives you a link error.