skyman skyman -3 years ago 102
Java Question

Accessing classes from libraries packaged in a jar

I have developed a plugin for an application. This plugin includes several libraries

When the plugin is called from the application I get a:

java.lang.NoClassDefFoundError: com/sun/media/imageioimpl/plugins/tiff/TIFFImageWriterSpi


I have confirmed that this class has been packaged with the plugin jar so I am guessing that I need to use some sort of classloader in the plugin jar to access this class - but not sure how to. Any help or re-direction appreciated.

Answer Source

You need to let the application know where the plugin jars are located so that it can load the required classes at run time. You can do that by specifying the Class-Path entry ,that refers to the plugin jars, in the META-INF/MANIFEST file of your application jar.

Class-Path: plugin-jar-name1 plugin-jar-name2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download