Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros;
00018
00019 import com.google.common.base.Preconditions;
00020 import com.google.common.collect.Lists;
00021
00022 import org.ros.exception.RosRuntimeException;
00023 import org.ros.internal.loader.CommandLineLoader;
00024 import org.ros.node.DefaultNodeMainExecutor;
00025 import org.ros.node.NodeConfiguration;
00026 import org.ros.node.NodeMain;
00027 import org.ros.node.NodeMainExecutor;
00028
00035 public class RosRun {
00036
00037 public static void printUsage() {
00038 System.err.println("Usage: java -jar my_package.jar com.example.MyNodeMain [args]");
00039 }
00040
00041 public static void main(String[] argv) throws Exception {
00042 if (argv.length == 0) {
00043 printUsage();
00044 System.exit(1);
00045 }
00046
00047 CommandLineLoader loader = new CommandLineLoader(Lists.newArrayList(argv));
00048 String nodeClassName = loader.getNodeClassName();
00049 System.out.println("Loading node class: " + loader.getNodeClassName());
00050 NodeConfiguration nodeConfiguration = loader.build();
00051
00052 NodeMain nodeMain = null;
00053 try {
00054 nodeMain = loader.loadClass(nodeClassName);
00055 } catch (ClassNotFoundException e) {
00056 throw new RosRuntimeException("Unable to locate node: " + nodeClassName, e);
00057 } catch (InstantiationException e) {
00058 throw new RosRuntimeException("Unable to instantiate node: " + nodeClassName, e);
00059 } catch (IllegalAccessException e) {
00060 throw new RosRuntimeException("Unable to instantiate node: " + nodeClassName, e);
00061 }
00062
00063 Preconditions.checkState(nodeMain != null);
00064 NodeMainExecutor nodeMainExecutor = DefaultNodeMainExecutor.newDefault();
00065 nodeMainExecutor.execute(nodeMain, nodeConfiguration);
00066 }
00067 }