execjarname.java

来自「kaffe Java 解释器语言,源码,Java的子集系统,开放源代码」· Java 代码 · 共 78 行

JAVA
78
字号
/* * ExecJarName.java * Execute a Jar file with a given named starting class. * * Copyright (c) 1998 *      Transvirtual Technologies, Inc.  All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */package kaffe.jar;import java.io.IOException;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.jar.JarFile;import kaffe.lang.AppClassLoader;public class ExecJarName {public static JarFile getJar(String path) {	JarFile jar = null;	try {		jar = new JarFile(path);	}	catch (IOException e) {		System.err.println("Can't access JAR file ``"		    + path + "'': " + e);		System.exit(1);	}	return jar;}public static void main(String[] args){	/* Check JAR file OK */	getJar(args[0]);	/* Get command to call */	String command = args[1];	/* Build new argument array */	String[] nargs = new String[args.length-2];	for (int i = 2; i < args.length; i++) {		nargs[i-2] = args[i];	}	/* Load in class */	try {		Class commandClass;		commandClass = AppClassLoader.getSingleton().			loadClass(command);		/* Build main(String[])V */		Class[] params = new Class[1];		params[0] = (new String[0]).getClass();		/* Build the invoke arguments */		Object[] iargs = new Object[1];		iargs[0] = nargs;		/* Get method and invoke */		Method meth = commandClass.getDeclaredMethod("main", params);		meth.invoke(null, iargs);	} catch (InvocationTargetException e) {		e.getTargetException().printStackTrace();		System.exit(1);	} catch (Exception e) {		e.printStackTrace();		System.exit(1);	}}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?