Java Code Examples for org.springframework.boot.loader.jar.JarFile#entries()

The following examples show how to use org.springframework.boot.loader.jar.JarFile#entries() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BootJarLaucherUtils.java    From tac with MIT License 5 votes vote down vote up
/**
 *
 * unpack jar to temp folder
 * @param jarFile
 * @return
 */
public static Integer unpackBootLibs(JarFile jarFile) throws IOException {

    Enumeration<JarEntry> entries = jarFile.entries();
    int count = 0;
    while (entries.hasMoreElements()) {

        JarEntry jarEntry = entries.nextElement();
        if (jarEntry.getName().startsWith(BOOT_INF_LIB) && jarEntry.getName().endsWith(".jar")) {
            getUnpackedNestedArchive(jarFile, jarEntry);
            count++;
        }
    }
    return count;
}
 
Example 2
Source File: FatJarHandle.java    From JavaProbe with GNU General Public License v3.0 3 votes vote down vote up
/**
 * fat jar 依赖文件的获取,多用于处理springboot打包的jar 传入的path是这样的 jar:file:/home/q/system/java/live/build/libs/live-33541.a12ed7cc.jar!/BOOT-INF/classes!/
 * @param jarpath
 * @param dependencyInfoList
 * @return
 */
public static List<DependencyInfo> getDependencyInfo(String jarpath, List<DependencyInfo> dependencyInfoList) {

    try {

        JarFile jarFile = new JarFile(new File(getROOTJar(jarpath)));

        Enumeration<JarEntry> jarEntryEnumeration = jarFile.entries();

        while (jarEntryEnumeration.hasMoreElements()) {

            JarEntry jarEntry = jarEntryEnumeration.nextElement();

            if (jarEntry.getName().endsWith(".jar")) { // 这里就暂时不匹配BOOT-INF/lib,考虑通用性

                JarFile inJarFile = jarFile.getNestedJarFile(jarEntry);
                DependencyInfo dependencyInfo = getJarInJardependcyInfo(inJarFile); // 获取资源

                if (dependencyInfo != null) dependencyInfoList.add(dependencyInfo);

            }
        }

    }
    catch (Exception e) {

        CommonUtil.writeStr("/tmp/jvm_error.txt","getDependencyInfo:\t" + e.getMessage());
    }

    return dependencyInfoList;
}
 
Example 3
Source File: FatJarHandle.java    From JavaProbe with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 获取Jarinjar中的资源
 * @param jarFile
 * @return
 */
public static DependencyInfo getJarInJardependcyInfo(JarFile jarFile) {

    try {

        Enumeration<JarEntry> jarEntryEnumeration = jarFile.entries();

        while (jarEntryEnumeration.hasMoreElements()) {

            JarEntry jarEntry= jarEntryEnumeration.nextElement();

            if (jarEntry.getName().endsWith("/pom.properties")) {

                Properties prop = new Properties();
                prop.load(jarFile.getInputStream(jarEntry));

                DependencyInfo dependencyInfo = new DependencyInfo(); // 存放依赖信息
                dependencyInfo.setArtifactId(prop.getProperty("artifactId"));
                dependencyInfo.setGroupId(prop.getProperty("groupId"));
                dependencyInfo.setVersion(prop.getProperty("version"));

                return dependencyInfo;
            }
        }

    }
    catch (Exception e) {

        CommonUtil.writeStr("/tmp/jvm_error.txt","getJarInJardependcyInfo:\t" + e.getMessage());
    }

    return null;

}