This article recommends [TOOLFK] online- JAVA code execution tool, provides JAVA code online execution function.
Website name: ToolFk
website link: https://www.toolfk.com/Tool
link: https://www.toolfk.com/tool-online-run-java
website link: https://www.toolfk.com/Tool
link: https://www.toolfk.com/tool-online-run-java
Code teaching
This tool [online JAVA code execution tool] depends on the Docker Java image
STEP 1 interface
STEP2
The execution code is as follows
static function dockerRunJava($code){
$ext = "java";
preg_match("/public\s*class(.*)\s*[extends|implement]*{/",$code,$matches);
$filename = "";
if($matches){
$filename = trim($matches[1]);
}
list($base_url,$filename) = self::runWriteFile("Java",$code,$ext,$filename);
$build_name = str_replace(".".$ext,"",$filename);
$full_path = $base_url."/".$filename;
return self::dockerRun($base_url,' java:latest /bin/bash -c "javac '.$filename.' && java '.$build_name.'" ',$ext,$full_path);
}
private static function dockerRun($base_url,$cmd,$pre,$full_path){
$random_name = $pre.mt_rand(1,999999999999);
$cmd = env("TOOL_DOCKER_PATH")." run --name {$random_name} --rm -v {$base_url}:/usr/src/{$pre} -w /usr/src/{$pre} {$cmd} 2>&1";
$res = shell_exec($cmd);
return $res;
}
留言
發佈留言