mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpilib] Use reflection to load main class, remove main from templates (#8627)
#8626 needs to switch to using reflection to load the robot class. Do that with this PR so it's separate. Also, remove the duplicated main files from the template, and instead fixup vscode to handle this properly.
This commit is contained in:
27
wpilibjExamples/src/main/java/org/wpilib/Executor.java
Normal file
27
wpilibjExamples/src/main/java/org/wpilib/Executor.java
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package org.wpilib;
|
||||
|
||||
import org.wpilib.framework.RobotBase;
|
||||
|
||||
/** This is the executor to launch template projects. */
|
||||
public final class Executor {
|
||||
private Executor() {}
|
||||
|
||||
/** Main initialization function. */
|
||||
public static void main(String... args) throws Throwable {
|
||||
// Load the class file for the robot.
|
||||
String packagePath = args[0];
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
System.out.println("Loading robot class: " + packagePath);
|
||||
|
||||
Class<?> robotClass = classLoader.loadClass(packagePath);
|
||||
|
||||
System.out.println("Starting robot: " + robotClass.getName());
|
||||
|
||||
RobotBase.startRobot(robotClass.asSubclass(RobotBase.class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user