Example #1
0
 @Nullable
 public static String getMainClassName(URL url) throws IOException {
   @NotNull URL u = new URL("jar", "", url + "!/");
   @NotNull JarURLConnection uc = (JarURLConnection) u.openConnection();
   Attributes attr = uc.getMainAttributes();
   return (attr != null) ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
 }
Example #2
0
  /**
   * Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was
   * defined.
   */
  public String getMainClassName() throws IOException {
    URL u = new URL("jar", "", url + "!/");
    JarURLConnection uc = (JarURLConnection) u.openConnection();

    if (uc.getEntryName() == null) System.out.println("No Entry Name");
    else System.out.println(uc.getEntryName());
    if (uc == null) System.out.println("Connection is null");
    Attributes attr = uc.getMainAttributes();
    if (attr != null) System.out.println("Attributes has size: " + attr.size());
    // output(attr);

    return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
  }