Skip to content

Commit

Permalink
De-hardcode the main class name.
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegratedQuantum committed Oct 1, 2021
1 parent 8c20b57 commit b969924
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/io/cubyz/dependency/DependencyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,18 @@ public static ArrayList<String> fetchDependencies(String pomURL, String absolute
} catch(Exception e) {
e.printStackTrace();
}
root = null;
return paths;
}

public static String findMainClass() {
MyNode plugins = root.get("project").get("build").get("plugins");
for(MyNode plugin : plugins.childs) {
if(plugin.get("artifactId").value.equals("maven-jar-plugin")) {
return plugin.get("configuration").get("archive").get("manifest").get("mainClass").value;
}
}
return "io.cubyz.client.GameLauncher";
}

private static void downloadDependencies(ArrayList<Dependency> dependencies, ArrayList<String> paths, String url) {
for(int i = 0; i < dependencies.size(); i++) {
Expand Down
3 changes: 2 additions & 1 deletion src/io/cubyz/github/GitHubConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static void downloadAndLaunchRelease(File folder) {

// Build the classpath:
ArrayList<String> libs = DependencyManager.fetchDependencies("https://github.com/PixelGuys/Cubyz/releases/download/"+tag+"/pom.xml", System.getProperty("user.home") + "/.cubyz", new File(folder, "pom.xml"));

// Put it all together as a classpath attribute:
char classpathSeperator = OSInfo.OS_FAMILY.equals("windows") ? ';' : ':';
String classpath = "";
Expand All @@ -132,7 +133,7 @@ public static void downloadAndLaunchRelease(File folder) {
classpath += folder.getAbsolutePath()+"/main.jar";

// Launch it:
ProcessBuilder pb = new ProcessBuilder("java", "-cp", classpath, "io.cubyz.client.GameLauncher");
ProcessBuilder pb = new ProcessBuilder("java", "-cp", classpath, DependencyManager.findMainClass());
pb.directory(folder);
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
Expand Down

0 comments on commit b969924

Please sign in to comment.