Springboot is packaged with multiple modules, and the module cannot load the data files packaged in this module.

springboot multi-module project, in which web project is packaged into jar to run, web project relies on tool module xx.jar
xx.jar to read data files through ClassLoader.getSystemResourceAsStream ("xx.txt"), running tool module alone can run
but web project depends on, can"t read the data file needed by xx.jar after being packaged into springboot executable jar
excuse me, how should I read this configuration file?
that is, how to access the files in the jar file of springboot / jar file in BOOT-INF/lib

Mar.11,2021

InputStream stream = ClassLoader.getSystemResourceAsStream ("xx.txt");

        if (stream == null) {
            URL url = ClassLoader.getSystemResource("BOOT-INF");
            if (url != null) {
                String path = url.getFile();
                path = path.substring(5, path.lastIndexOf("!"));
                JarFile jarFile = new JarFile(path);
                JarEntry entry = jarFile.getJarEntry("BOOT-INF/lib/xx.jar");
                InputStream is = jarFile.getInputStream(entry);
                String folder = System.getProperty("java.io.tmpdir");
                File file = new File(folder, "xx.jar");
                OutputStream output = new FileOutputStream(file);
                int bytesRead = 0;
                byte[] buffer = new byte[8192];
                while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
                    output.write(buffer, 0, bytesRead);
                }
                output.close();
                is.close();
                JarFile jar = new JarFile(file);
                JarEntry jarEntry = jar.getJarEntry("xx.txt");
                stream = jar.getInputStream(jarEntry);
            }
        }
Menu