Loading Classpath Resources

1 view
Skip to first unread message

Steven Waldren

unread,
Sep 22, 2009, 5:53:30 PM9/22/09
to kcjava
Hello,

I have run into a little issue. I want to be able to load some XSLT
files that are in the Classpath (org.mine.xslt.samplexslt.xsl). I
tried to use MyClass.class.getResourceAsStream("/org/mine/xslt/
samplexslt.xsl"), but I then run into problems because the
samplexslt.xsl has an <xsl:import href"./date/difference/
date.difference.xsl"/> (since it in in a sub-package). When I load
the samplexslt.xsl it throws an error because it cannot find
date.difference.xslt.

When I change the xsl:import href to "src/org/mine/xslt/date/
difference/date.difference.xsl" The XSLT will compile. This does not
seem to be a good approach.

Any direction on best practices to load non-java files that reference
other files from the classpath?

Thanks for any help.

Best,
Steven
--
Steven Waldren
swal...@gmail.com
GnuPGP Key: https://keyserver2.pgp.com/vkd/DownloadKey.event?keyid=0xEE7A9BE0A97A081E

Jon Brisbin

unread,
Sep 22, 2009, 5:57:32 PM9/22/09
to kcj...@googlegroups.com
I don't have any examples handy, but I've done something like this before by registering a protocol handler and using urls like "classpath:/org/mypackage/etc.xml".

jb


Thanks!

Jon Brisbin

hanasaki

unread,
Sep 22, 2009, 8:24:57 PM9/22/09
to kcj...@googlegroups.com
I had this issue in the past and used a customer resolver:

ref:
http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/EntityResolver.html
http://xml.apache.org/commons/components/resolver/resolver-article.html
>> swal...@gmail.com <mailto:swal...@gmail.com>
>> GnuPGP Key:
>> https://keyserver2.pgp.com/vkd/DownloadKey.event?keyid=0xEE7A9BE0A97A081E
>>
>>
>>
>> Thanks!
>>
>> Jon Brisbin
>> http://jbrisbin.com/
>>
>
> >

--

=================================================================
= Management is doing things right; =
= Leadership is doing the right things. - Peter Drucker =
=================================================================
Reply all
Reply to author
Forward
0 new messages