Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Read resource from "Plug-in from existing JAR archives"
Read resource from "Plug-in from existing JAR archives" [message #990653] Thu, 13 December 2012 15:22 Go to next message
Giovanni Senile is currently offline Giovanni SenileFriend
Messages: 5
Registered: August 2012
Junior Member
I need Docx4j library in my RCP application.
So i create a new "Plug-in from existing JAR archives" and put all needed JARs there.

But when I use it, I have an error:

ERROR org.docx4j.utils.ResourceUtils .getResource line 40 - Couldn't get resource: org/docx4j/convert/out/pdf/viaXSLFO/docx2fo.xslt


Here the Docx4j source code line:

ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {  // IKVM (v.0.44.0.5) doesn't set context classloader 
  loader = ResourceUtils.class.getClassLoader();
}


How can I allow docx4j JAR to read its resources?
(obviously in my 'docx4j plugin' org/docx4j/convert/out/pdf/viaXSLFO/docx2fo.xslt exists)

Thank you!
Re: Read resource from "Plug-in from existing JAR archives" [message #991121 is a reply to message #990653] Mon, 17 December 2012 12:19 Go to previous message
Giovanni Senile is currently offline Giovanni SenileFriend
Messages: 5
Registered: August 2012
Junior Member
Sorry. Here the complete source code:

public static java.io.InputStream  getResource(String filename) throws java.io.IOException
    {
        // Try to load resource from jar.
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (loader == null) {  // IKVM (v.0.44.0.5) doesn't set context classloader 
            loader = ResourceUtils.class.getClassLoader();
        }

        java.net.URL url = loader.getResource(filename);
                
        if (url == null) {
        	log.error("Couldn't get resource: " + filename);
        }

        // Get the jar file
//      JarURLConnection conn = (JarURLConnection) url.openConnection();

        java.io.InputStream is = url.openConnection().getInputStream();

        return is;
    }


BTW, the matter is: I don't want to change source code, so how can I let the "plugin from jar" to find its resources?
Previous Topic:How to use Command and Handler concept for SWT Widget.
Next Topic:Navigate From HTML link to Source Code Line
Goto Forum:
  


Current Time: Fri Dec 19 18:25:26 GMT 2014

Powered by FUDForum. Page generated in 0.01870 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software