Add port and jvmArgs options

This commit is contained in:
2026-05-23 23:48:47 +02:00
parent 50e5a17666
commit 37254a60f0
3 changed files with 33 additions and 10 deletions
+2 -3
View File
@@ -5,10 +5,9 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="98c311c3-6130-4449-9bcb-07029b56b776" name="Changes" comment=""> <list default="true" id="98c311c3-6130-4449-9bcb-07029b56b776" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/src/main/java/org/strassburger/mcrun/downloader/SpigotServerJarDownloader.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/strassburger/mcrun/downloader/ServerJarDownloader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/strassburger/mcrun/downloader/ServerJarDownloader.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/org/strassburger/mcrun/RunServerMojo.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/strassburger/mcrun/RunServerMojo.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -56,7 +55,7 @@
<updated>1779565206518</updated> <updated>1779565206518</updated>
<workItem from="1779565207730" duration="57000" /> <workItem from="1779565207730" duration="57000" />
<workItem from="1779565274563" duration="632000" /> <workItem from="1779565274563" duration="632000" />
<workItem from="1779565913273" duration="6524000" /> <workItem from="1779565913273" duration="6820000" />
</task> </task>
<servers /> <servers />
</component> </component>
+1 -1
View File
@@ -7,7 +7,7 @@
<groupId>org.strassburger</groupId> <groupId>org.strassburger</groupId>
<artifactId>mc-run</artifactId> <artifactId>mc-run</artifactId>
<version>0.0.8</version> <version>0.0.9</version>
<packaging>maven-plugin</packaging> <packaging>maven-plugin</packaging>
<name>MCRun Maven Plugin</name> <name>MCRun Maven Plugin</name>
@@ -6,7 +6,6 @@ import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.Parameter;
import org.strassburger.mcrun.downloader.PaperServerJarDownloader;
import org.strassburger.mcrun.downloader.ServerJarDownloadException; import org.strassburger.mcrun.downloader.ServerJarDownloadException;
import org.strassburger.mcrun.downloader.ServerJarDownloader; import org.strassburger.mcrun.downloader.ServerJarDownloader;
@@ -14,6 +13,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
@Mojo(name = "run", defaultPhase = LifecyclePhase.PACKAGE) @Mojo(name = "run", defaultPhase = LifecyclePhase.PACKAGE)
public class RunServerMojo extends AbstractMojo { public class RunServerMojo extends AbstractMojo {
@@ -38,6 +39,12 @@ public class RunServerMojo extends AbstractMojo {
@Parameter(defaultValue = "true") @Parameter(defaultValue = "true")
private boolean acceptEula; private boolean acceptEula;
@Parameter
private List<String> jvmArgs = new ArrayList<>();
@Parameter
private Integer port;
@Override @Override
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Server directory: " + serverDirectory.getAbsolutePath()); getLog().info("Server directory: " + serverDirectory.getAbsolutePath());
@@ -61,12 +68,13 @@ public class RunServerMojo extends AbstractMojo {
} catch (ServerJarDownloadException e) { } catch (ServerJarDownloadException e) {
throw new MojoExecutionException("Failed to download server jar", e); throw new MojoExecutionException("Failed to download server jar", e);
} }
if (acceptEula) acceptEula(); if (acceptEula) acceptEula();
ProcessBuilder pb = new ProcessBuilder( List<String> command = buildCommand();
"java", "-Xmx" + memory, "-Xms" + memory, getLog().info("Starting server with command: " + String.join(" ", command));
"-jar", serverJarName, "--nogui"
); ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(serverDirectory); pb.directory(serverDirectory);
pb.inheritIO(); pb.inheritIO();
Process process; 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 { private void acceptEula() throws MojoExecutionException {
File eula = new File(serverDirectory, "eula.txt"); File eula = new File(serverDirectory, "eula.txt");
if (eula.exists()) return; if (eula.exists()) return;
@@ -92,4 +116,4 @@ public class RunServerMojo extends AbstractMojo {
throw new MojoExecutionException("Failed to write eula.txt: " + e.getMessage(), e); throw new MojoExecutionException("Failed to write eula.txt: " + e.getMessage(), e);
} }
} }
} }