Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] jrxml loaing issue from classpath.

Kapil,

That's not a very portable way of finding the resource.

I have no idea what the classloader for tomcat is, but the URLClassLoader (a subclass of which is the classloader for the webapp in jetty)  will load the path of the resource sought by adding it to its urls in turn.
For example:
If I have:
 /home/janb/tmp/xxx
                          /jrx
                            foo.blah
and

URLClassLoader l = new URLClassLoader(new URL[]{new URL("file:///home/janb/tmp/xxx/")},Thread.currentThread().getContextClassLoader());
URL u = l.getResource("../../jrx/foo.blah");

The URLClassLoader concatenates to result in "file:/home/janb/tmp/xxx/../../jrx/foo.blah", and this file does not exist.

If you use instead ClassLoader.getResource("jrx/foo.blah") the URLClassLoader can find it. The java bootloader can find it too, if you run the above lines at the command line, and I would assume that tomcat's loader would find it as well.

Jan



On Tue, 10 Dec 2019 at 16:26, kapil gupta <kapilgupta82@xxxxxxxxx> wrote:
Depicting the structure in better way:
  • WEB-INF
    • classes
  • jrxml
    • ABC.jrxml
So WEB-INF and jrxml packages are at same level.

On Tue, Dec 10, 2019 at 9:57 AM kapil gupta <kapilgupta82@xxxxxxxxx> wrote:
Hi,
I am facing issue where I am trying to load jrxml files from classpath, it is working fine in Tomcat server but same code not working on jetty.

War structure
  - WEB-INF
- classes
  - jrxml
- ABC.jrxml


I am trying to load file via below code:
Thread.currentThread().getContextClassLoader().getResourceAsStream("../../jrxml/ABC.jrxml);

Please let me know how can I solve this problem.

Thanks & Regards
Kapil
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users


--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD


Back to the top