Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » ClassLoader.getSystemResourceAsStream() does not work as expected
ClassLoader.getSystemResourceAsStream() does not work as expected [message #297907] Sun, 22 January 2006 12:05 Go to next message
Eclipse UserFriend
Originally posted by: stefanuhrig.gmx.net

Hi,

I'm developing an RCP-application that depends on third-party libraries (JAR-archives).

I've packaged all necessary .jar-archives into a separate plug-in that I created by using the "Plug-in from existing JAR archives"
wizard. Afterwards I made my RCP-application dependent on this plug-in.

I can access and use all the classes inside the JAR archives, it works fine. However, one of the libraries uses
ClassLoader.getSystemResourceAsStream() to access a file inside its archive. This attempt fails and returns null (although it works
when the library is not used inside the plug-in).

Has anyone an idea why this fails and how to get it working, so that the library can access its file?

Thanks in advance,
Stefan
Re: ClassLoader.getSystemResourceAsStream() does not work as expected [message #297922 is a reply to message #297907] Sun, 22 January 2006 20:57 Go to previous messageGo to next message
Eclipse UserFriend
Stefan Uhrig wrote:

> Hi,
>
> I'm developing an RCP-application that depends on third-party libraries
> (JAR-archives).
>
> I've packaged all necessary .jar-archives into a separate plug-in that I
> created by using the "Plug-in from existing JAR archives" wizard.
> Afterwards I made my RCP-application dependent on this plug-in.
>
> I can access and use all the classes inside the JAR archives, it works
> fine. However, one of the libraries uses
> ClassLoader.getSystemResourceAsStream() to access a file inside its
> archive. This attempt fails and returns null (although it works when the
> library is not used inside the plug-in).
>
> Has anyone an idea why this fails and how to get it working, so that the
> library can access its file?
>
> Thanks in advance,
> Stefan
you can change method with ClassLoader.getSystemResourceAsStream() - it is
bad behaviour
another choice is that you define own classloader, add archive which this
method require and call method - after this return to normal eclipse
classloader (in finally clause)
Re: ClassLoader.getSystemResourceAsStream() does not work as expected [message #297931 is a reply to message #297922] Mon, 23 January 2006 06:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

It sounds like the library is badly written -- using the System classloader is unnecessary almost all of the time. It should almost certainly be getResourceAsStream(), which picks up the runtime classpath and thus would avoid this problem. If you've got the source to the library, you can fix/recompile this yourself; if not, you could get into .class hackery to fix the problem by replacing the string getSystemResourceAsStream with a hex editor to getResourceAs Stream; though there's also a length that you'd have to change too. The Apache BCEL might help you do this.

Alex.
Re: ClassLoader.getSystemResourceAsStream() does not work as expected [message #297951 is a reply to message #297931] Mon, 23 January 2006 09:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: stefanuhrig.gmx.net

I have access to the source of the library, so I modified it to use
ClassLoader.getResourceAsStream(), and it works fine!

Thanks,
Stefan


"Alex Blewitt" <automatic@javalobby.org> schrieb

It sounds like the library is badly written -- using the System classloader
is unnecessary almost all of the time. It should almost certainly be
getResourceAsStream(), which picks up the runtime classpath and thus would
avoid this problem. If you've got the source to the library, you can
fix/recompile this yourself;
Re: ClassLoader.getSystemResourceAsStream() does not work as expected [message #297954 is a reply to message #297907] Mon, 23 January 2006 09:35 Go to previous message
Eclipse UserFriend
Stefan Uhrig wrote:
> Hi,
>
> I'm developing an RCP-application that depends on third-party libraries
> (JAR-archives).
>
> I've packaged all necessary .jar-archives into a separate plug-in that I
> created by using the "Plug-in from existing JAR archives" wizard.
> Afterwards I made my RCP-application dependent on this plug-in.
>
> I can access and use all the classes inside the JAR archives, it works
> fine. However, one of the libraries uses
> ClassLoader.getSystemResourceAsStream() to access a file inside its
> archive. This attempt fails and returns null (although it works when the
> library is not used inside the plug-in).

One of the libraries uses ClassLoader#getSystemResourceAsStream() to
access a file inside the library? Or inside your plugin?

Like the other mentioned, it sounds like a bad use of the system class
loader. Why don't more people use
getClass().getClassLoader().getResourceAsStream(*)?

Later,
PW
Previous Topic:Deploy, Running the plugin from outside Eclipse
Next Topic:Eclipse3.1 won't checkout from CVSNT 2.5.02...
Goto Forum:
  


Current Time: Sun May 04 12:18:23 EDT 2025

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

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

Back to the top