문제

ProjectA
    -src/main/java
        -com.myApp.accessor
            -resourceAccessor.java
    -src/test/resources
        -context.xml
    -target/test-classes/context.xml

ProjectB (dependent on ProjectA)
    -src/main/java
        -xyz.java

Now I need to access the context.xml from ProjectB. What I'm doing is:

Class resourceAccessor{

    public static void loadFile(){
       ....
       this.getClass().getResources("/context.xml").getPath;
       ....
    }
}

in xyz, I have

resourceAccessor.loadFile();

But this throws null pointer exception.

도움이 되었습니까?

해결책

Solved the issue by putting the context.xml into src/main/resources/com.myApp.accessor/context.xml. Then use

getClass().getResource("context.xml").getPath()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top