I have a maven project with 2 modules. There is a crawler module which depends on the core module. Each module has it’s own config.ini file in src/main/resources/ and one single main class per module.
Now I want to start the NewsCrawler like this:
mvn exec:java -Dexec.mainClass="org.aksw.simba.rdflivenews.NewsCrawler"
This works for loading the crawlers own config file but fails to load the config file from core-module:
NewsCrawler.CONFIG = new Config(new Ini(File.class.getResourceAsStream("/newscrawler-config.ini")));
RdfLiveNews.CONFIG = new Config(new Ini(File.class.getResourceAsStream("/rdflivenews-config.ini")));
The second config load fails with a NullPointerException. I checked the jar file and the config file is inside. The strange thing is that same two lines work in the test cases. Also with eclipse I can start the main of the class without any problems.
Here is a well-functioning source code of your example.
dezip, then on the command line, go to the directory containing the parent pom then do :
Do something like this to know where you are when calling getResourceAsStream() :
Also try to remove
/beforenewscrawler-config.ini. It depends on where you put your files in the hierarchy.getResourceAsStreamsearch the CLASSPATH, not the source path.You may also use
this.getClass().getResourceAsStream()instead ofFile.class.getResourceAsStream().It could be a solution to copy the src/main/resource to your target/test-classes by configuring resource in your pom.xml :
and call getResourceAsStream() with a quasi-full-path :