/*
 * #%L
 * ImageJ software for multidimensional image processing and analysis.
 * %%
 * Copyright (C) 2009 - 2012 Board of Regents of the University of
 * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
 * Institute of Molecular Cell Biology and Genetics.
 * %%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 * The views and conclusions contained in the software and documentation are
 * those of the authors and should not be interpreted as representing official
 * policies, either expressed or implied, of any organization.
 * #L%
 */

package imagej;

import java.io.File;
import java.io.IOException;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

/**
 * TODO
 *
 * @author Johannes Schindelin
 */
public class JarLauncher {
	public static void main(String[] args) {
		if (args.length < 1) {
			System.err.println("Missing argument");
			System.exit(1);
		}
		String[] shifted = new String[args.length - 1];
		System.arraycopy(args, 1, shifted, 0, shifted.length);
		launchJar(args[0], shifted);
	}

	// helper to launch .jar files (by inspecting their Main-Class
	// attribute).
	public static void launchJar(String jarPath, String[] arguments) {
		JarFile jar = null;
		try {
			jar = new JarFile(jarPath);
		} catch (IOException e) {
			System.err.println("Could not read '" + jarPath + "'.");
			System.exit(1);
		}
		Manifest manifest = null;
		try {
			manifest = jar.getManifest();
		} catch (IOException e) { }
		if (manifest == null) {
			System.err.println("No manifest found in '"
					+ jarPath + "'.");
			System.exit(1);
		}
		Attributes attributes = manifest.getMainAttributes();
		String className = attributes == null ? null :
			attributes.getValue("Main-Class");
		if (className == null) {
			System.err.println("No main class attribute found in '"
					+ jarPath + "'.");
			System.exit(1);
		}
		ClassLoaderPlus loader = ClassLoaderPlus.get(new File(jarPath));
		ClassLauncher.launch(loader, className, arguments);
	}
}

@@ -1994,16 +1994,17 @@
  TODO%0A *
+ 
 %0A * @aut
@@ -2058,16 +2058,17 @@
 ncher %7B%0A
+%0A
 %09public 
@@ -2084,16 +2084,22 @@
 id main(
+final 
 String%5B%5D
@@ -2200,16 +2200,22 @@
 ;%0A%09%09%7D%0A%09%09
+final 
 String%5B%5D
@@ -2352,11 +2352,16 @@
 %0A%0A%09/
-/ h
+**%0A%09 * H
 elpe
@@ -2418,12 +2418,8 @@
 lass
-%0A%09//
  att
@@ -2427,16 +2427,21 @@
 ibute).%0A
+%09 */%0A
 %09public 
@@ -2462,16 +2462,22 @@
 unchJar(
+final 
 String j
@@ -2483,16 +2483,22 @@
 jarPath,
+ final
  String%5B
@@ -2572,32 +2572,40 @@
 arPath);%0A%09%09%7D
- 
+%0A%09%09
 catch (
+final 
 IOException 
@@ -2684,24 +2684,65 @@
 em.exit(1);%0A
+%09%09%09return; // NB: Avoids warnings below.%0A
 %09%09%7D%0A%09%09Manife
@@ -2809,16 +2809,24 @@
 %0A%09%09%7D
- 
+%0A%09%09
 catch (
+final 
 IOEx
@@ -2837,17 +2837,42 @@
 ion e) %7B
- 
+%0A%09%09%09// no action needed%0A%09%09
 %7D%0A%09%09if (
@@ -2929,38 +2929,33 @@
 fest found in '%22
-%0A%09%09%09%09%09
+ 
 + jarPath + %22'.%22
@@ -2978,20 +2978,67 @@
 t(1);%0A%09%09
-%7D%0A%09%09
+%09return; // NB: Avoids warnings below.%0A%09%09%7D%0A%09%09final 
 Attribut
@@ -3085,16 +3085,22 @@
 es();%0A%09%09
+final 
 String c
@@ -3109,17 +3109,20 @@
 ssName =
- 
+%0A%09%09%09
 attribut
@@ -3140,20 +3140,17 @@
 ? null :
-%0A%09%09%09
+ 
 attribut
@@ -3265,14 +3265,9 @@
 n '%22
-%0A%09%09%09%09%09
+ 
 + ja
@@ -3306,16 +3306,22 @@
 ;%0A%09%09%7D%0A%09%09
+final 
 ClassLoa

Clean up JarLauncher style