I have a (maybe simple) question. In my code I want to know whether there are one or more folder in a classpath or not. First things first: my code is working when using IDE, but not when it runs in a jar file. I understood that there is the way with - especially in Spring Boot - the class PathMatchingPatternResolver to get the resources. I have done this, but I can't get my code working under *.jar. The situation is as follows: I want to look at a certain path if there are certain folder to get their names. If there are such folder, the names of them will be saved in a List. I need this List in further action. But how to get the folder from *.jar?
Here is what I have done so far:
public List<String> loadSupportedRecords(Meta metaFromTaxCase) {
List<String> vastRecordTypes = new ArrayList<>();
Map<String, String> values = new HashMap<>();
values.put(TAX_TYPE, metaFromTaxCase.getTaxonomie().getKey());
values.put(FISCAL_YEAR, metaFromTaxCase.getVeranlagungszeitraum());
values.put(TAXONOMIE_VERSION, metaFromTaxCase.getVersionDerTaxonomie());
var path = replaceVariablesInPathWithMapValues(vastConfigTemplatePath, values);
var indexOfRepo = path.lastIndexOf("{record-type}/");
var lengthOfVar = "{record-type}".length();
var subPath = path.substring(0, indexOfRepo + lengthOfVar);
try {
for (Resource resource : resourcePatternResolver.getResources(subPath)) {
vastRecordTypes.add(resource.getFilename()); // <-- This does not work
// I know that this does not work, but this is my newest commit.
// I tried with File Object and used the "listFiles()" method,
// but also failed.
}
return vastRecordTypes;
} catch (IOException e) {
throw new ResourceNotFoundException(
String.format(CLASSPATH_ERROR_MESSAGE, path, e.getMessage()));
}
}
Is there any way to get the folder names in IDE AND in *.jar running? Thank you all for helping me as good as you can.