@@ -7,6 +7,7 @@ import java.io.BufferedReader
77import java.io.IOException
88import java.io.InputStreamReader
99import java.nio.file.Path
10+ import java.nio.file.Paths
1011import java.util.concurrent.Callable
1112import java.util.concurrent.Executors
1213import java.util.concurrent.TimeUnit
@@ -103,20 +104,31 @@ class JavaExecutor {
103104}
104105
105106class CommandLineArgument (
106- val classPaths : String ,
107- val mainClass : String? ,
108- val policy : Path ,
109- val memoryLimit : Int ,
110- val arguments : List <String >
107+ val classPaths : String ,
108+ val mainClass : String? ,
109+ val policy : Path ,
110+ val memoryLimit : Int ,
111+ val arguments : List <String >,
111112) {
112- fun toList (): List <String > {
113- return (listOf (
114- " java" ,
115- " -Xmx" + memoryLimit + " M" ,
116- " -Djava.security.manager" ,
117- " -Djava.security.policy=$policy " ,
118- " -ea" ,
119- " -classpath"
120- ) + classPaths + mainClass + arguments).filterNotNull()
121- }
113+ fun toList (): List <String > {
114+ return (listOf (
115+ getJavaPath(),
116+ " -Xmx" + memoryLimit + " M" ,
117+ " -Djava.security.manager" ,
118+ " -Djava.security.policy=$policy " ,
119+ " -ea" ,
120+ " -classpath"
121+ ) + classPaths + mainClass + arguments).filterNotNull()
122+ }
123+ }
124+
125+ fun getJavaPath (): String {
126+ // Determine the Java executable path based on the OS
127+ val javaHome = System .getProperty(" java.home" ) ? : return " java"
128+ val javaBinPath = if (System .getProperty(" os.name" )?.lowercase()?.contains(" win" ) == true ) {
129+ Paths .get(javaHome, " bin" , " java.exe" ).toString()
130+ } else {
131+ Paths .get(javaHome, " bin" , " java" ).toString()
132+ }
133+ return javaBinPath
122134}
0 commit comments