001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.system.main;
018
019 import java.util.Collections;
020
021 import org.apache.geronimo.gbean.AbstractName;
022 import org.apache.geronimo.gbean.AbstractNameQuery;
023 import org.apache.geronimo.kernel.Jsr77Naming;
024 import org.apache.geronimo.kernel.repository.Artifact;
025
026 /**
027 * @version $Revision: 487175 $ $Date: 2006-12-14 03:10:31 -0800 (Thu, 14 Dec 2006) $
028 */
029 public class ClientCommandLine extends CommandLine {
030 /**
031 * Command line entry point called by executable jar
032 * @param args command line args
033 */
034 public static void main(String[] args) {
035 log.info("Client startup begun");
036 if(args.length == 0) {
037 System.out.println();
038 System.out.println("ERROR: No arguments");
039 showHelp();
040 System.exit(1);
041 } else if(args[0].equals("--help") || args[0].equals("-h") || args[0].equals("/?")) {
042 showHelp();
043 System.exit(0);
044 }
045 try {
046 Artifact configuration = Artifact.create(args[0]);
047 String[] clientArgs = new String[args.length -1];
048 System.arraycopy(args, 1, clientArgs, 0, clientArgs.length);
049 new ClientCommandLine(configuration, clientArgs);
050 } catch (Exception e) {
051 ExceptionUtil.trimStackTrace(e);
052 e.printStackTrace();
053 System.exit(2);
054 throw new AssertionError();
055 }
056 }
057
058 private static void showHelp() {
059 System.out.println();
060 System.out.println("syntax: java -jar bin/client.jar config-name [app arg] [app arg] ...");
061 System.out.println();
062 System.out.println("The first argument should identify the Geronimo configuration that");
063 System.out.println("contains the application client you want to run.");
064 System.out.println();
065 System.out.println("The rest of the arguments will be passed as arguments to the");
066 System.out.println("application client when it is started.");
067 System.out.println();
068 }
069
070
071 public ClientCommandLine(Artifact configuration, String[] args) throws Exception {
072 Jsr77Naming naming = new Jsr77Naming();
073 //this kinda sucks, but resource adapter modules deployed on the client insist on having a
074 //J2EEApplication name component
075 AbstractName baseName = naming.createRootName(configuration, configuration.toString(), "J2EEApplication");
076 AbstractNameQuery baseNameQuery = new AbstractNameQuery(baseName);
077 invokeMainGBean(Collections.singletonList(configuration), baseNameQuery, "main", args);
078 }
079 }