Question

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.

Was it helpful?

Solution

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

getClass().getResource("context.xml").getPath()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top