View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  package org.apache.geronimo.system.main;
19  
20  import java.util.Collections;
21  
22  import org.apache.geronimo.gbean.AbstractName;
23  import org.apache.geronimo.gbean.AbstractNameQuery;
24  import org.apache.geronimo.kernel.Jsr77Naming;
25  import org.apache.geronimo.kernel.repository.Artifact;
26  
27  /**
28   * @version $Revision: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
29   */
30  public class ClientCommandLine extends CommandLine {
31      /**
32       * Command line entry point called by executable jar
33       * @param args command line args
34       */
35      public static void main(String[] args) {
36          log.info("Client startup begun");
37          if(args.length == 0) {
38              System.out.println();
39              System.out.println("ERROR: No arguments");
40              showHelp();
41              System.exit(1);
42          } else if(args[0].equals("--help") || args[0].equals("-h") || args[0].equals("/?")) {
43              showHelp();
44              System.exit(0);
45          }
46          try {
47              Artifact configuration = Artifact.create(args[0]);
48              String[] clientArgs = new String[args.length -1];
49              System.arraycopy(args, 1, clientArgs, 0, clientArgs.length);
50              new ClientCommandLine(configuration, clientArgs);
51          } catch (Exception e) {
52              ExceptionUtil.trimStackTrace(e);
53              e.printStackTrace();
54              System.exit(2);
55              throw new AssertionError();
56          }
57      }
58  
59      private static void showHelp() {
60          System.out.println();
61          System.out.println("syntax:   java -jar bin/client.jar config-name [app arg] [app arg] ...");
62          System.out.println();
63          System.out.println("The first argument should identify the Geronimo configuration that");
64          System.out.println("contains the application client you want to run.");
65          System.out.println();
66          System.out.println("The rest of the arguments will be passed as arguments to the");
67          System.out.println("application client when it is started.");
68          System.out.println();
69      }
70  
71  
72      public ClientCommandLine(Artifact configuration, String[] args) throws Exception {
73          Jsr77Naming naming = new Jsr77Naming();
74          //this kinda sucks, but resource adapter modules deployed on the client insist on having a
75          //J2EEApplication name component
76          AbstractName baseName = naming.createRootName(configuration, configuration.toString(), "J2EEApplication");
77          AbstractNameQuery baseNameQuery = new AbstractNameQuery(baseName);
78          invokeMainGBean(Collections.singletonList(configuration), baseNameQuery, "main", args);
79      }
80  }