KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > utilint > JarMain


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: JarMain.java,v 1.4 2006/10/30 21:14:29 bostic Exp $
7  */

8
9 package com.sleepycat.je.utilint;
10
11 import java.lang.reflect.Method JavaDoc;
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 JavaDoc USAGE = "usage: java <utility> [options...]";
27     private static final String JavaDoc PREFIX = "com.sleepycat.je.util.";
28
29     public static void main(String JavaDoc[] args) {
30         try {
31             if (args.length < 1) {
32                 usage("Missing utility name");
33             }
34             Class JavaDoc cls = Class.forName(PREFIX + args[0]);
35
36             Method JavaDoc mainMethod = cls.getMethod
37                 ("main", new Class JavaDoc[] { String JavaDoc[].class });
38
39             String JavaDoc[] mainArgs = new String JavaDoc[args.length - 1];
40             System.arraycopy(args, 1, mainArgs, 0, mainArgs.length);
41
42             mainMethod.invoke(null, new Object JavaDoc[] { mainArgs });
43         } catch (Throwable JavaDoc e) {
44             usage(e.toString());
45         }
46     }
47
48     private static void usage(String JavaDoc msg) {
49         System.err.println(msg);
50     System.err.println(USAGE);
51     System.exit(-1);
52     }
53 }
54
Popular Tags