In that case, you should use:
InputStream is =
request.getServletContext().getResourceAsStream("/jrxml/ABC.jrxml");
Works portably on all servlet containers.
Jan
On Tue, 10 Dec 2019 at 17:13, kapil gupta <[email protected]> wrote:
> Jan,
>
> Thanks for the reply.
> The ClassLoader.getResource() works fine when the resources are within
> src/main/resources package. But my jrxml is in parallel to WEB-INF package.
> So it works fine with below structure:
>
> - WEB-INF
> - classes
> - jrxml
> - ABC.jrxml
>
>
> But my hierarchy is different, it is in parallel to WEB-INF like below:
>
> - WEB-INF
> - classes
> - jrxml
> - ABC.jrxml
>
>
> On Tue, Dec 10, 2019 at 11:32 AM Jan Bartel <[email protected]> wrote:
>
>> 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 <[email protected]> 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 <[email protected]>
>>> 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
>>> [email protected]
>>> To change your delivery options, retrieve your password, or unsubscribe
>>> from this list, visit
>>> https://www.eclipse.org/mailman/listinfo/jetty-users
>>
>>
>>
>> --
>> Jan Bartel <[email protected]>
>> www.webtide.com
>> *Expert assistance from the creators of Jetty and CometD*
>>
>> _______________________________________________
>> jetty-users mailing list
>> [email protected]
>> To change your delivery options, retrieve your password, or unsubscribe
>> from this list, visit
>> https://www.eclipse.org/mailman/listinfo/jetty-users
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://www.eclipse.org/mailman/listinfo/jetty-users
--
Jan Bartel <[email protected]>
www.webtide.com
*Expert assistance from the creators of Jetty and CometD*
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users