[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:
Thad House
2026-02-21 14:35:26 -08:00
committed by GitHub
parent 793b0a3187
commit 44441daad7
93 changed files with 167 additions and 2140 deletions

View 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));
}
}