static JarFileWithEntryClass findOnlyEntryClass ( Iterable < File > jarFiles ) throws IOException { List < JarFileWithEntryClass > jarsWithEntryClasses = new ArrayList <> ( ) ; for ( File jarFile : jarFiles ) { findEntryClass ( jarFile ) . ifPresent ( entryClass -> jarsWithEntryClasses . add ( new JarFileWithEntryClass ( jarFile , entryClass ) ) ) ; } int size = jarsWithEntryClasses . size ( ) ; if ( size == 0 ) { throw new NoSuchElementException ( "No JAR with manifest attribute for entry class" ) ; } if ( size == 1 ) { return jarsWithEntryClasses . get ( 0 ) ; } // else: size > 1 throw new IllegalArgumentException ( "Multiple JARs with manifest attribute for entry class: " + jarsWithEntryClasses ) ; }
Returns a JAR file with its entry class as specified in the manifest .