In my application I load resources in this manner:
WinProcessor.class.getResource('repository').toString();
and this gives me:
file:/root/app/repository (and I replace 'file:' with empty string)
This works fine when I run my application from the IDE, but when I run the jar of my application:
java -jar app.jar
The path becomes:
jar:/root/app.jar!/repository
is there any way to solve this problem?
I’ll use the ‘repository’ dir name in order to create this:
ConfigurationContext ctx = (ConfigurationContext) ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryString, null);
In the same manner, I’ll get one file name (instead of a dir) and I’ll use it this way:
System.setProperty('javax.net.ssl.trustStore', fileNameString)
It sounds like you’re then trying to load the resource using a
FileInputStreamor something like that. Don’t do that: instead of callinggetResource, callgetResourceAsStreamand read the data from that.(You could load the resources from the URL instead, but calling
getResourceAsStreamis a bit more convenient.)EDIT: Having seen your updated answer, it seems other bits of code rely on the data being in a physical single file in the file system. The answer is therefore not to bundle it in a jar file in the first place. You could check whether it’s in a separate file, and if not extract it to a temporary file, but that’s pretty hacky IMO.