elasticsearch-beyonder icon indicating copy to clipboard operation
elasticsearch-beyonder copied to clipboard

multi module spring boot project can't support

Open lwpk110 opened this issue 6 years ago • 14 comments

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/

lwpk110 avatar Aug 13 '19 09:08 lwpk110

Which version are you using? I think it's fixed by this https://github.com/dadoonet/elasticsearch-beyonder/pull/43.

dadoonet avatar Aug 13 '19 09:08 dadoonet

v 5.0

lwpk110 avatar Aug 13 '19 10:08 lwpk110

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

dadoonet avatar Aug 13 '19 10:08 dadoonet

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 avatar Aug 13 '19 10:08 lwpk110

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.

lwpk110 avatar Aug 13 '19 10:08 lwpk110

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

dadoonet avatar Aug 13 '19 10:08 dadoonet

ok, i will try it, ty

lwpk110 avatar Aug 13 '19 10:08 lwpk110

Any news?

dadoonet avatar Jan 15 '20 20:01 dadoonet

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.

FrostbittenKing avatar Feb 13 '21 12:02 FrostbittenKing

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).

dadoonet avatar May 31 '21 15:05 dadoonet

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();
}

lwpk110 avatar Jun 01 '21 08:06 lwpk110

@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?

dadoonet avatar Jun 03 '21 05:06 dadoonet

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);
                }
            }

lwpk110 avatar Jun 07 '21 08:06 lwpk110

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 avatar Jun 16 '21 16:06 dadoonet