Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't work inside JAR #11

Open
alabotski opened this issue Jul 27, 2021 · 3 comments
Open

Don't work inside JAR #11

alabotski opened this issue Jul 27, 2021 · 3 comments

Comments

@alabotski
Copy link

It's my resource folder
image

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 =(

@gurpreet-
Copy link
Collaborator

gurpreet- commented Aug 1, 2021

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?

@alabotski
Copy link
Author

The problem was . That I had spring boot jar.

In normal jar structure, all work fine

@gurpreet-
Copy link
Collaborator

Is this problem resolved then @alabotski?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants