It's been like 8-10 hours since I encounter that problem and it really bugs me. So hopefully someone would give me a hint what I'm doing wrong.
Issue I'm using maven shaded plugin to pack my maven app to jar file, the problem which I encounter is that in Eclipse when I'm running my app all is sound, but when I try to run my app as jar file:
java -jar <my-file>
I get:
Exception in thread 'main' java.lang.NullPointerException
at start.my.App.main<App.java:60>
My application works as filter and processor for files within directory from which my app is started. Traverse method simply returns list of files within directory in which my jar file is located:
@Override
public List<File> traverse(String directory) {
File directory = new File(directory);
List<File> resultList = new ArrayList<File>();
File[] fList = directory.listFiles();
resultList.addAll(Arrays.asList(fList));
for (File file : fList) {
if (file.isDirectory()) {
resultList.addAll(traverse(file.getAbsolutePath()));
}
}
return resultList;
}
The line in which this problem occurs:
WalkerResult walkerResult =
walker.traverse(ClassLoader.getSystemClassLoader()
.getResource(".")
.getPath());
What's inside traverse method should return path to my jar file which I'm running, I think I'm doing something wrong as when I pass as path to traverse method which looks like:
WalkerResult walkerResult =
walker.traverse("C:\\Users\\Downloads");
all is fine in IDE and as in jar application.
Thanks for any hints in advance.