Example usage for org.springframework.boot.loader.tools MainClassFinder findSingleMainClass

List of usage examples for org.springframework.boot.loader.tools MainClassFinder findSingleMainClass

Introduction

In this page you can find the example usage for org.springframework.boot.loader.tools MainClassFinder findSingleMainClass.

Prototype

public static String findSingleMainClass(File rootFolder) throws IOException 

Source Link

Document

Find a single main class from the given rootFolder .

Usage

From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java

protected String getMainClass(Archive archive) {
    try {/*w  ww .  java 2 s . com*/
        Manifest manifest = archive.getManifest();
        String mainClass = null;
        if (manifest != null) {
            mainClass = manifest.getMainAttributes().getValue("Start-Class");
        }
        if (mainClass == null) {
            throw new IllegalStateException("No 'Start-Class' manifest entry specified in " + this);
        }
        return mainClass;
    } catch (Exception e) {
        try {
            File root = new File(archive.getUrl().toURI());
            if (archive instanceof ExplodedArchive) {
                return MainClassFinder.findSingleMainClass(root);
            } else {
                return MainClassFinder.findSingleMainClass(new JarFile(root), "/");
            }
        } catch (Exception ex) {
            throw new IllegalStateException("Cannot find main class", e);
        }
    }
}