Basil Bourque
Basil Bourque

Reputation: 339837

JDBC driver not found, even after placing its jar in Tomcat home /lib folder, when run in Netbeans 8

When using Tomcat 8 to run my Servlets while programming in NetBeans 8 under Java 8, I placed my JDBC driver jar in the correct location: Tomcat's home holder, in its /lib folder, amongst the catalina.jar and servlet-api.jar and such.

When trying to run, NetBeans shows errors saying the JDBC driver cannot be found.

I tried both the Build button and the Clean & Build button.

I tried manually deleting contents of the Private Configuration Folder (Catalina Base) folder that I had established when configuring the connection between NetBeans & Tomcat.

I tried quitting and restarting NetBeans.

Why is my JDBC jar not found?

Upvotes: 0

Views: 994

Answers (1)

Basil Bourque
Basil Bourque

Reputation: 339837

Solution

You need to remove that Tomcat configuration from NetBeans. Then recreate that configuration.

Explanation

Apparently when first run from NetBeans, a list of jar files in that /lib folder is somehow recorded. Jars added later are ignored.

Details

You can verify this list by examining the NetBeans↔Tomcat configuration’s properties.

To access properties, context-click the Tomcat server’s item in NetBeans Services > Servers list. Choose Properties.

screen shot of NetBeans > Services panel > Servers > Tomcat configuration item > Properties (menu item)

Click the Classes tab to see a list of jars known from the Tomcat /lib folder. The two JDBC driver jars shown here did not appear when I first dropped them into /lib. They appeared only after removing and re-creating the NetBeans↔Tomcat configuration.

screen shot of Services panel > Servers > Tomcat configuration item > Properties > Servers (window) > Classes (tab)

To remove the NetBeans↔Tomcat configuration, context-click the Tomcat server's item in NetBeans Services > Servers list. Choose Remove.

screen shot of Services panel > Servers > Tomcat configuration item > Remove

Re-create the Tomcat configuration by context-clicking the Servers grouping, and choose Add Server….

screen shot of NetBeans > Services panel > Servers > Add Server (menu item)

Now you can check the Properties > Classes again, and you'll see any extra jars added now appear in the list. Your JDBC driver will now be available to your servlets.


Aside: I found that NetBeans was cranky about my re-using the previous Private Configuration Folder (Catalina Base) folder. I had to manually delete the folder from the file system (the Finder on a Mac), create a new folder in the same place, and pasted to give the new folder the same old name.

Upvotes: 0

Related Questions