01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: JarMain.java,v 1.4.2.2 2008/01/07 15:14:18 cwl Exp $
07: */
08:
09: package com.sleepycat.je.utilint;
10:
11: import java.lang.reflect.Method;
12:
13: /**
14: * Used as the main class for the manifest of the je.jar file, and so it is
15: * executed when running: java -jar je.jar. The first argument must be the
16: * final part of the class name of a utility in the com.sleepycat.je.util
17: * package, e.g., DbDump. All following parameters are passed to the main
18: * method of the utility and are processed as usual.
19: *
20: * Apart from the package, this class is ambivalent about the name of the
21: * utility specified; the only requirement is that it must be a public static
22: * class and must contain a public static main method.
23: */
24: public class JarMain {
25:
26: private static final String USAGE = "usage: java <utility> [options...]";
27: private static final String PREFIX = "com.sleepycat.je.util.";
28:
29: public static void main(String[] args) {
30: try {
31: if (args.length < 1) {
32: usage("Missing utility name");
33: }
34: Class cls = Class.forName(PREFIX + args[0]);
35:
36: Method mainMethod = cls.getMethod("main",
37: new Class[] { String[].class });
38:
39: String[] mainArgs = new String[args.length - 1];
40: System.arraycopy(args, 1, mainArgs, 0, mainArgs.length);
41:
42: mainMethod.invoke(null, new Object[] { mainArgs });
43: } catch (Throwable e) {
44: usage(e.toString());
45: }
46: }
47:
48: private static void usage(String msg) {
49: System.err.println(msg);
50: System.err.println(USAGE);
51: System.exit(-1);
52: }
53: }
|