开发者

Changing the directory from which ClassLoader looks in for Web Application

开发者 https://www.devze.com 2023-03-10 12:15 出处:网络
The web application I am working on uses a certain resource. For testing purposes, I want it to use a different resource with the same name but in different directory. I use classloader to load the re

The web application I am working on uses a certain resource. For testing purposes, I want it to use a different resource with the same name but in different directory. I use classloader to load the resources. Currently it always loads the resource from the test/resources directory. I want to be able to tell it to be able to get it from a different directory (when not testing) without changing the code.

This is how I used ClassLoader:

    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    InputStream file =loader.getResourceAsStream("resource.xml");

So, when I deploy the web-app (jetty container), I need to also modify something or somehow give it a different classpath or place to look since I have resources that are different for test开发者_运维技巧ing and the main use.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号