简体   繁体   中英

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.

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

you need to add com.sun.media:jai_imageio:1.1 dependency into your pom.xml . you can find dependency belwo:

<dependency>
    <groupId>com.sun.media</groupId>
    <artifactId>jai_imageio</artifactId>
    <version>1.1</version>
</dependency>

if your are using simple project you need to download jai_imageio.jar jar file from below link and put into lib directory and add into build path:

http://www.java2s.com/Code/Jar/j/Downloadjaiimageiojar.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM