WojtusJ
WojtusJ

Reputation: 1318

Keeps getting Class Not Found Exception for Postgres driver in eclipse plugin

I am developing a simple plugin for eclipse, which has one view connecting to Postgres. I have installed postgres which is running fine. I have a driver: postgresql-9.0-801.jdbc4.jar which was provided with the installation package.

Now I'm trying to connect to database using the code:

try {
    Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnfe) {
    cnfe.printStackTrace();
    return false;
}

Of course, I've added mentioned JAR to class path: right click on project > preferences > Java Build Path It is added to "Libraries".

Still I get an error:

java.lang.ClassNotFoundException: org.postgresql.Driver

I have also checked the box in "Order and Export" tab.

What am I doing wrong?

Upvotes: 0

Views: 1621

Answers (1)

Marko Topolnik
Marko Topolnik

Reputation: 200158

You said it's a plugin? Then you should NOT add it to lib path directly like that. You are developing an OSGi bundle and you must open MANIFEST.MF in the manifest editor, then at the Runtime tab, Classpath section, add your JAR. Also check at the Build tab that it's included in the build. Yeah, OSGi, another name for simplicity. Enjoy.

Upvotes: 1

Related Questions