1

Topic: Question on ClassLoader.getSystemResource

! In Java I in transit: port of the main project and to unwinding it is impossible to understand with behavior of function ClassLoader.getSystemResource. A problem. There is a test project, which   (result  the project),  and supposed in a local repository. In this  at start the resource by a call of type ClassLoader.getSystemResource ("abc.xml") is searched returned null and all falls. The necessary file in project resources is. The project   through maven. The Test project  also is launched through maven: mvn clean compile exec:java the Packet  is called X.Y.Z and lies in source codes on an appropriate way main\java\X\Y\Z. abc.xml lies in a folder main\resources. That is clarified: 1. In the project there is a unit tests, as one of them I adapted a test project. All is launched it is a command mvn clean validate compile test. In frames a test unit all for some reason works. . Thus in a folder target\classes lies abc.xml and it is function ClassLoader.getSystemResource 2. I go to simple test project and I enclose in a folder target\classes a file abc.xml. I launch, function ClassLoader.getSystemResource does not find abc.xml. 3. If to move a file abc.xml from main\resources in main\resources\X\Y\Z, to replace ClassLoader.getSystemResource on Class.getResource,   and to launch a test project Class.getResource finds a file inside  . The purpose: it is necessary to play back behavior of a test project (namely ClassLoader.getSystemResource) in frames a test unit. Now quits that ClassLoader.getSystemResource at start from a test project does not find a file, and the test unit finds in frames. Though they lie on the same way target\classes. What to do?

2

Re: Question on ClassLoader.getSystemResource

Hello, StatujaLeha, you wrote: Briefly: on that it and system classloader that at it in presence only the classes necessary for loading JVM. SL> What to do? To use application resources through ClassLoader#getResource () Since the required file is in jar applications getSystemResource it will not see

3

Re: Question on ClassLoader.getSystemResource

Hello, xBlackCat, you wrote: BC> Briefly: on that it and system classloader that at it in presence only the classes necessary for loading JVM. Here this piece strange works, finds a resource is not present... SL>> What to do? BC> to use application resources through ClassLoader#getResource () Yes, I made it for a fix. I should write a unit the test which will fall if the fix is not present, and to transit with a fix. But while so it turns out that at start test  all falls, and at start in frames the unit of tests of the project all apprx. While made a variant with start test  through java.lang. Process. BC> since the required file is in jar applications getSystemResource it will not see 1. We put abc.xml in a root of a folder with resources. 2.   3. mvn compile package for test application 2. We print output ClassLoader.getSystemResource ("abc.xml") 3. An output: jar: file:/path/to/package.jar!/abc.xml

4

Re: Question on ClassLoader.getSystemResource

Hello, StatujaLeha, you wrote: It is necessary to understand hierarchy ClassLoader' and their operation. If in an operating time it is used app-server, which   in process of operation the code with getSystemResource will not work. Anyway, specificity getSystemResource is that, that there was a possibility to address to initially loaded classes since classes can be redefined in .