src/main/java/de/vandermeer/execs/Gen_ExecJarScripts.java
protected boolean inExecJar(){
		Class<Gen_ExecJarScripts> clazz = Gen_ExecJarScripts.class;
		String className = clazz.getSimpleName() + ".class";
		String classPath = clazz.getResource(className).toString();
		if (!classPath.startsWith("jar")) {
			System.err.println(this.getAppName() + ": not started in a jar, cannot proceed");
			return false;
		}

		String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
		Manifest manifest;
		try {
			manifest = new Manifest(new URL(manifestPath).openStream());
		}
		catch (IOException ex) {
			System.err.println(this.getAppName() + ": exception while retrieving manifest: " + ex.getMessage());
			return false;
		}
		Attributes attr = manifest.getMainAttributes();
		if(StringUtils.isBlank(attr.getValue("Main-Class"))){
			System.err.println(this.getAppName() + ": no main class in manifest, probably not an executable JAR, cannot continue");
			return false;
		}
		return true;
	}
protected boolean inExecJar(){
		Class<Gen_ExecJarScripts> clazz = Gen_ExecJarScripts.class;
		String className = clazz.getSimpleName() + ".class";
		String classPath = clazz.getResource(className).toString();
		if (!classPath.startsWith("jar")) {
			System.err.println(this.getAppName() + ": not started in a jar, cannot proceed");
			return false;
		}

		String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
		Manifest manifest;
		try {
			manifest = new Manifest(new URL(manifestPath).openStream());
		}
		catch (IOException ex) {
			System.err.println(this.getAppName() + ": exception while retrieving manifest: " + ex.getMessage());
			return false;
		}
		Attributes attr = manifest.getMainAttributes();
		if(StringUtils.isBlank(attr.getValue("Main-Class"))){
			System.err.println(this.getAppName() + ": no main class in manifest, probably not an executable JAR, cannot continue");
			return false;
		}
		return true;
	}
protected boolean inExecJar ( ) { Class < Gen_ExecJarScripts > clazz = Gen_ExecJarScripts . class ; String className = clazz . getSimpleName ( ) + ".class" ; String classPath = clazz . getResource ( className ) . toString ( ) ; if ( ! classPath . startsWith ( "jar" ) ) { System . err . println ( this . getAppName ( ) + ": not started in a jar, cannot proceed" ) ; return false ; } String manifestPath = classPath . substring ( 0 , classPath . lastIndexOf ( "!" ) + 1 ) + "/META-INF/MANIFEST.MF" ; Manifest manifest ; try { manifest = new Manifest ( new URL ( manifestPath ) . openStream ( ) ) ; } catch ( IOException ex ) { System . err . println ( this . getAppName ( ) + ": exception while retrieving manifest: " + ex . getMessage ( ) ) ; return false ; } Attributes attr = manifest . getMainAttributes ( ) ; if ( StringUtils . isBlank ( attr . getValue ( "Main-Class" ) ) ) { System . err . println ( this . getAppName ( ) + ": no main class in manifest, probably not an executable JAR, cannot continue" ) ; return false ; } return true ; }
Tests if the class is run from an executable JAR.
@return true if run from an executable JAR (JAR with Main-Class in manifest), false otherwise with errors printed
Tests if the class is run from an executable JAR .