public static void main(String[] args) {
        try {

            List jarsList = new ArrayList();

            URL url = JarDeploy.class.getResource("");
            JarFile bundleJar = ((JarURLConnection) url.openConnection()).getJarFile();

            Manifest manifest = bundleJar.getManifest();

            Attributes mainAttributes = manifest.getMainAttributes();
            String bundleClassPath = mainAttributes.getValue("Bundle-ClassPath");
            if (bundleClassPath == null) {
                bundleClassPath = "lib/";
            }

            String localClassPath = mainAttributes.getValue("Local-ClassPath");

            File bundleFile = new File(bundleJar.getName());

            List localJars = getLocalJars(localClassPath, bundleFile);

            jarsList.addAll(localJars);


            List bundleJars = extractJars(bundleJar, bundleClassPath);
            jarsList.addAll(bundleJars);

            String realMain = mainAttributes.getValue("Bundle-Main-Class");
            if (realMain == null && args.length > 0) {
                realMain = args[0];
                String[] remaining = new String[args.length - 1];
                System.arraycopy(args, 1, remaining, 0, args.length - 1);
                args = remaining;
            }

            if (realMain == null) {
                System.err.println("Failed to find Bundle-Main-Class.  Please provide as first argument or in the Bundle-Main-Class manifest entry");
                System.exit(-1);
            }

            for (Iterator iter = jarsList.iterator(); iter.hasNext(); ) {
                File file = (File) iter.next();
                addFileToClassPath(file);
            }
            jarsList.add(new File(bundleJar.getName()));
            loadedJars = jarsList;
            Class loadClass = ClassLoader.getSystemClassLoader().loadClass(realMain);

            Method main = loadClass.getMethod("main", new Class[]{args.getClass()});
            if (main == null) {
                throw new Exception("Could not find main in class: " + realMain);
            }
            if (!Modifier.isStatic(main.getModifiers())) {
                throw new Exception("Main is not static in class: " + realMain);
            }

            main.invoke(null, new Object[]{args});

        } catch (InvocationTargetException te) {
            Logger.getLogger("JarDeploy").log(Level.SEVERE, "Unexpected Exception has occurred", te.getTargetException());
        } catch (Exception e) {
            Logger.getLogger("JarDeploy").log(Level.SEVERE, "Unexpected Exception has occurred", e);
        }
    }