Don't work inside JAR
It's my resource folder

My code
@Component
public class TableConfigFactory {
private static final String UPLOAD_DIR = "upload";
...
public TableConfigFactory(ObjectMapper objectMapper) throws IOException, URISyntaxException {
this.objectMapper = objectMapper;
URL url = ResourceLoader.getThePathToTheJarWeAreIn(TableConfigFactory.class);
log.info("{}", url);
Path uploadPath = FileLoader.get()
.load(UPLOAD_DIR, TableConfigFactory.class)
.toPath();
}
When I run it in Idea all work fine When I run it from jar
I have such error
Caused by: java.io.IOException: Failed to list contents of file:/Users/XXX/Workspace/word/build/libs/word-1.0-SNAPSHOT.jar!/BOOT-INF/classes!/upload
ResourceLoader.getThePathToTheJarWeAreIn(TableConfigFactory.class) return such string
12:08:27.882 [main] INFO com.test.TableConfigFactory - jar:file:/Users/XXX/Workspace/word/build/libs/word-1.0-SNAPSHOT.jar!/BOOT-INF/classes!/
And
// Test if we are in a JAR and if we are
// then do the following...
if (isJarFile(fullJarPathURL))
return false =(
Inside the isJarFile method can you try and print the debug statement here?
private boolean isJarFile(URL jarUrl) {
// ...
catch (IOException | IllegalStateException | SecurityException e) {
logger.debug("This is not a JAR file due to {}", e.getMessage()); <------- here
}
// ...
}
Or maybe it doesn't throw an exception but fails due to lack of manifest file within the JAR due to this code:
private boolean isJarFile(URL jarUrl) {
// ...
// Successfully opened the jar file. Check if there's a manifest
// This is probably not necessary
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
return true;
}
Do you have a manifest file inside your JAR?
The problem was . That I had spring boot jar.
In normal jar structure, all work fine
Is this problem resolved then @alabotski?