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

multi module spring boot project can't support #76

Open
lwpk110 opened this issue Aug 13, 2019 · 14 comments
Open

multi module spring boot project can't support #76

lwpk110 opened this issue Aug 13, 2019 · 14 comments
Labels

Comments

@lwpk110
Copy link

lwpk110 commented Aug 13, 2019

i integrate es with spring-elasticsearch,my project is multi module project. when use idea tool run app, it's ok,but when i package it to jar , it doesn't work. i debug it,found 'ResourceList' cause the problem. jar file can't read valid classpaht resource, it can't read the resource of sub moudule. expect fix it!
for exam:
jar:file:/C:/Users/steven/Desktop/delivery/xb-lbs-service-1.0.0.jar!/BOOT-INF/lib/xb-lbs-core-1.0.0-SNAPSHOT.jar!/elasticsearch/client/rest/

@dadoonet
Copy link
Owner

Which version are you using? I think it's fixed by this #43.

@lwpk110
Copy link
Author

lwpk110 commented Aug 13, 2019

v 5.0

@dadoonet
Copy link
Owner

That's why. It was fixed in 6.5 and 7.0 IIRC.

@lwpk110
Copy link
Author

lwpk110 commented Aug 13, 2019

but i hacked this class to my project, it still can't work.
log below:
f.p.elasticsearch.tools.ResourceList : ==> jar prefix:[BOOT-INF/lib/xb-lbs-core-1.0.0-SNAPSHOT.jar/fr/pilato/elasticsearch/tools/ResourceList.class]

@lwpk110
Copy link
Author

lwpk110 commented Aug 13, 2019

by the way, i package my app to a jar will occur the problem ,by command 'java -jar app.jar', when i use IDE to run will work ok.

@dadoonet
Copy link
Owner

What did you do exactly? Could you reproduce the problem with 7.0?

@lwpk110
Copy link
Author

lwpk110 commented Aug 13, 2019

ok, i will try it, ty

@dadoonet
Copy link
Owner

Any news?

@FrostbittenKing
Copy link

Can confirm, doesn't work in multi module projects. I fixed it by using the maven resources plugin and copying the index configs from the other module into the actual packaged module. Didn't look through the code too thorough, but it seems like it can't locate additional resources in the BOOT-INF/lib folders.

@dadoonet
Copy link
Owner

It would help if you could share a full simple (the easiest one as possible) which could show the problem. And if you have a fix what is it actually (in another commit).

@lwpk110
Copy link
Author

lwpk110 commented Jun 1, 2021

Sorry, I just saw it. I think there may be some problems in obtaining path of source file. like that

 String filepath;
if(ResourceUtils.isFileURL(resource.getURL())){  //File url
		filepath= 	((FileSystemResource) resource).getPath();
}else {  //jar url @see {@link ResourceUtils#isJarUrl}
		filepath = ((ClassPathResource) resource).getPath();
}

@dadoonet
Copy link
Owner

dadoonet commented Jun 3, 2021

@lwpk110 where this code is coming from? Any idea on how to fix this issue?
Does anyone could provide a simple sample project that shows the problem so I can may be work on a fix?

@lwpk110
Copy link
Author

lwpk110 commented Jun 7, 2021

I've found the problem. In a multi module project, when the main module depends on another sub module, and the sub module is responsible for handling es.when the main module is packaged as jar, and the main module also needs to parse the sub module jar package when the app runs.
i think we must improve this part,and let it support sub-jar resolving:
{@link fr.pilato.elasticsearch.tools.ResourceList#getResources(String)}

 if (dirURL.getProtocol().equals("jar")) {
            /* A JAR path */
            logger.trace("found a jar file resource: {}", dirURL);
            String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); //strip out only the JAR file
            JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
            Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
            Set<String> result = new HashSet<>(); //avoid duplicates in case it is a subdirectory
            while(entries.hasMoreElements()) {
                String name = entries.nextElement().getName();
                if (name.startsWith(root)) { //filter according to the path
                    String entry = name.substring(root.length());
                    int checkSubdir = entry.indexOf("/");
                    if (checkSubdir >= 0) {
                        // if it is a subdirectory, we just return the directory name
                        entry = entry.substring(0, checkSubdir);
                    }
                    result.add(entry);
                }
            }

@dadoonet
Copy link
Owner

Yeah. I guess so.

it would help a lot if someone could provide a sample project which reproduces the problem. That way I could work on a patch and make sure it solves it.

or better, if someone could provide the patch itself 😉

@dadoonet dadoonet added the bug label Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants