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