public static void main(String[] args) {
    if (args.length < 1 || args[0].equals("-h") || args[0].equals("--help")) {
      System.out.println(usage);
      return;
    }

    // Copy args, because CommandFormat mutates the list.
    List<String> argsList = new ArrayList<String>(Arrays.asList(args));
    CommandFormat cf = new CommandFormat(0, Integer.MAX_VALUE, "-glob", "-jar");
    try {
      cf.parse(argsList);
    } catch (UnknownOptionException e) {
      terminate(1, "unrecognized option");
      return;
    }

    String classPath = System.getProperty("java.class.path");

    if (cf.getOpt("-glob")) {
      // The classpath returned from the property has been globbed already.
      System.out.println(classPath);
    } else if (cf.getOpt("-jar")) {
      if (argsList.isEmpty() || argsList.get(0) == null ||
          argsList.get(0).isEmpty()) {
        terminate(1, "-jar option requires path of jar file to write");
        return;
      }

      // Write the classpath into the manifest of a temporary jar file.
      Path workingDir = new Path(System.getProperty("user.dir"));
      final String tmpJarPath;
      try {
        tmpJarPath = FileUtil.createJarWithClassPath(classPath, workingDir,
          System.getenv())[0];
      } catch (IOException e) {
        terminate(1, "I/O error creating jar: " + e.getMessage());
        return;
      }

      // Rename the temporary file to its final location.
      String jarPath = argsList.get(0);
      try {
        FileUtil.replaceFile(new File(tmpJarPath), new File(jarPath));
      } catch (IOException e) {
        terminate(1, "I/O error renaming jar temporary file to path: " +
          e.getMessage());
        return;
      }
    }
  }
@Test
  public void testUnrecognized() {
    try {
      Classpath.main(new String[] { "--notarealoption" });
      fail("expected exit");
    } catch (ExitUtil.ExitException e) {
      assertTrue(stdout.toByteArray().length == 0);
      String strErr = new String(stderr.toByteArray(), UTF8);
      assertTrue(strErr.contains("unrecognized option"));
    }
  }