测试编译class文件
parent
89f6cba0e2
commit
4000b47c8c
|
@ -0,0 +1,30 @@
|
||||||
|
package com.muyu.test;
|
||||||
|
|
||||||
|
import com.muyu.domain.constants.Result;
|
||||||
|
|
||||||
|
import javax.tools.JavaCompiler;
|
||||||
|
import javax.tools.ToolProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:qdm
|
||||||
|
* @Package:com.muyu.test
|
||||||
|
* @Project:engine
|
||||||
|
* @name:JavaClass
|
||||||
|
* @Date:2024/9/5 16:00
|
||||||
|
*/
|
||||||
|
public class JavaClass {
|
||||||
|
public static Result<Object> compile(String fileName) {
|
||||||
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||||
|
String[] strings = {"-classpath", "/home/lib", "-verbose", "-d", "/home/lib", fileName};
|
||||||
|
//编译任务
|
||||||
|
int result = compiler.run(null, null, null, strings);
|
||||||
|
//检查编译结果
|
||||||
|
if (result == 0) {
|
||||||
|
System.out.println("编译成功,生成的.class文件位于源代码同目录");
|
||||||
|
} else {
|
||||||
|
System.out.println("编译失败");
|
||||||
|
}
|
||||||
|
String externalClassFilePath = "/home";
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue