Add port and jvmArgs options
This commit is contained in:
@@ -6,7 +6,6 @@ import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.strassburger.mcrun.downloader.PaperServerJarDownloader;
|
||||
import org.strassburger.mcrun.downloader.ServerJarDownloadException;
|
||||
import org.strassburger.mcrun.downloader.ServerJarDownloader;
|
||||
|
||||
@@ -14,6 +13,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mojo(name = "run", defaultPhase = LifecyclePhase.PACKAGE)
|
||||
public class RunServerMojo extends AbstractMojo {
|
||||
@@ -38,6 +39,12 @@ public class RunServerMojo extends AbstractMojo {
|
||||
@Parameter(defaultValue = "true")
|
||||
private boolean acceptEula;
|
||||
|
||||
@Parameter
|
||||
private List<String> jvmArgs = new ArrayList<>();
|
||||
|
||||
@Parameter
|
||||
private Integer port;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
getLog().info("Server directory: " + serverDirectory.getAbsolutePath());
|
||||
@@ -61,12 +68,13 @@ public class RunServerMojo extends AbstractMojo {
|
||||
} catch (ServerJarDownloadException e) {
|
||||
throw new MojoExecutionException("Failed to download server jar", e);
|
||||
}
|
||||
|
||||
if (acceptEula) acceptEula();
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(
|
||||
"java", "-Xmx" + memory, "-Xms" + memory,
|
||||
"-jar", serverJarName, "--nogui"
|
||||
);
|
||||
List<String> command = buildCommand();
|
||||
getLog().info("Starting server with command: " + String.join(" ", command));
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(command);
|
||||
pb.directory(serverDirectory);
|
||||
pb.inheritIO();
|
||||
Process process;
|
||||
@@ -82,6 +90,22 @@ public class RunServerMojo extends AbstractMojo {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> buildCommand() {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
cmd.add("java");
|
||||
cmd.add("-Xmx" + memory);
|
||||
cmd.add("-Xms" + memory);
|
||||
cmd.addAll(jvmArgs);
|
||||
cmd.add("-jar");
|
||||
cmd.add(serverJarName);
|
||||
cmd.add("--nogui");
|
||||
if (port != null) {
|
||||
cmd.add("--port");
|
||||
cmd.add(String.valueOf(port));
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
||||
private void acceptEula() throws MojoExecutionException {
|
||||
File eula = new File(serverDirectory, "eula.txt");
|
||||
if (eula.exists()) return;
|
||||
@@ -92,4 +116,4 @@ public class RunServerMojo extends AbstractMojo {
|
||||
throw new MojoExecutionException("Failed to write eula.txt: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user