Skip to content

Commit

Permalink
In Java args start at 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed May 15, 2024
1 parent fce6562 commit 59cba43
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/main/java/net/neoforged/devlaunch/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,19 @@ public static void main(String[] args) throws Throwable {
throw new IllegalArgumentException("DevLaunch requires at least one argument: the main class.");
}

String mainClass = newArgs.get(1);
newArgs.remove(1);

Method mainMethod;
try {
mainMethod = Class.forName(mainClass).getMethod("main", String[].class);
mainMethod = Class.forName(newArgs.get(0)).getMethod("main", String[].class);
} catch (ReflectiveOperationException e) {
throw new IllegalArgumentException("Could not find main class or main method. Given main class: " + mainClass, e);
throw new IllegalArgumentException("Could not find main class or main method. Given main class: " + newArgs.get(0), e);
}

try {
mainMethod.invoke(null, (Object) newArgs.toArray(String[]::new));
mainMethod.invoke(null, (Object) newArgs.subList(1, newArgs.size()).toArray(String[]::new));
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (ReflectiveOperationException e) {
throw new IllegalArgumentException("Could not invoke main class: " + mainClass, e);
throw new IllegalArgumentException("Could not invoke main class: " + newArgs.get(0), e);
}
}

Expand Down

0 comments on commit 59cba43

Please sign in to comment.