RosRun.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49