Access a resource from a depending project

62 views Asked by At
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.

1

There are 1 answers

0
Edmond On BEST ANSWER

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

getClass().getResource("context.xml").getPath()