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