17 January 2011

Class path problems in eclipse plug-ins

As I mentioned in a previous post, out of desperation I added the DB2 jar to an eclipse plug-in. I then innocently tried to load it using:

try {
} catch (ClassNotFoundException e) {
    Activator.logError("getConnection", e);
    throw e;
return DriverManager.getConnection("jdbc:db2://servername", "user", "pwd");

This did not work. Eclipse plug-ins have their own class loader and the DB2 jar must be added to the plug-in classpath.

Open the plugin.xml and select the 'Runtime' tab. In the 'Classpath' section select 'Add...' and choose the DB2.jar (and any other JARs which are needed).

Best practice (I would guess) would be to have separate plug-ins for each external library (log4j, db2 etc).

No comments:

Post a Comment