I have a maven project that builds a xmlreader class that has 2 constructors. One that takes a external filename and one default that loads a resource.
The default constructor works for test, but doesn't find the file when I execute program with default parameters. Changing the way I access the resource makes the test fail and maven stops building. I have extracted the jar and the file is located there.
Here is the constructor:
public XmlReader() {
this.filename = getClass().getResource("/Default.xml").getPath();
this.git = new GitClass();
this.cucumber = new CucumberClass();
this.execute = new ExecuteClass();
}
Errormessage:
5030 [main] ERROR - File file:/Users/andreasjoelsson/XmlReader/target/XmlReader-1.0-SNAPSHOT.jar!/Default.xml not found.
5030 [main] DEBUG - Context: init of reader: false
JUnit test:
@Test
public void test2() {
XmlReader testObject = new XmlReader();
// Subject to change as it's the default config to run.
assertEquals(true, testObject.init());
assertEquals(25, testObject.getExecute().getMaxUsers());
assertEquals(true, testObject.getExecute().isRepeatFeature());
assertEquals(1, testObject.getExecute().getSecondsBetweenIncrease());
assertEquals(2, testObject.getExecute().getUsersIncreasedEachInterval());
assertEquals(20, testObject.getExecute().getWaitAfterRampSeconds());
System.out.println(testObject.toString());
}
So the package that I execute test on works, but not when I run it outside of maven.