javaclasspatheclipse-classpath

Understanding External Class Folder


Whilst learning to develop servlets I added C:\Program Files\Apache\Tomcat8\lib\servlet-api.jar to my J2EE project's build path to get the servlets to work. All fine:

I then decided to instead add the entire folder C:\Program Files\Apache\Tomcat8\lib as an "External Class Folder" and suddenly I'm back to "javax.servlet cannot be resolved".

This seems to make no sense especially when compared to how eclipse adds the Tomcat library - it looks almost identical:

[[3]

I guess the questions are:

  1. What is wrong with my including an entire folder as a "library"?
  2. How would one properly add a folder so that it appears as a proper library as in the "Apache Tomcat v8.0" library eclipse adds via wizard

Solution

  • OK, it seems adding an external class folder means "adding a folder containing class files" and not, as one might hope, "adding a folder containing .jar files containing class files". Thus eclipse, finding no class files in my tomcat/lib folder fails to see the class files inside servlet-api.jar.

    As for my 2nd question it's possible to create "User Libraries" as follows:

    1. Window -> Preferences
    2. Java -> Build Path -> User Libraries
    3. Click New... button and enter a name
    4. Click the new library and then "Add External JARs..."
    5. Browse to tomcat/lib and add all .jar files

    To reference this library:

    1. Project -> Build Path -> Configure Build Path
    2. Add Library... button
    3. Choose "User Library"
    4. Choose your library