Skip to content

Commit 0b0f2fc

Browse files
committed
Provide the same java for child process in JavaExecutor as parent one
1 parent 6f203b8 commit 0b0f2fc

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.io.BufferedReader
77
import java.io.IOException
88
import java.io.InputStreamReader
99
import java.nio.file.Path
10+
import java.nio.file.Paths
1011
import java.util.concurrent.Callable
1112
import java.util.concurrent.Executors
1213
import java.util.concurrent.TimeUnit
@@ -103,20 +104,31 @@ class JavaExecutor {
103104
}
104105

105106
class 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

Comments
 (0)