feat():测试
parent
b62c181969
commit
ae63ab2c0e
|
@ -74,15 +74,6 @@ public class OSSFileLoad {
|
|||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
System.out.println("----------------------------");
|
||||
try {
|
||||
String command = "javac -cp . " + ":/home/app.jar" + fileName;
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
process.waitFor();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("----------------------------");
|
||||
//对路径里的.java文件进行编译
|
||||
System.out.println("第一步");
|
||||
SourceCodeCompiler.javaCompilerPath("home/");
|
||||
|
|
|
@ -9,6 +9,7 @@ import javax.tools.StandardJavaFileManager;
|
|||
import javax.tools.ToolProvider;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SourceCodeCompiler {
|
||||
|
@ -61,7 +62,7 @@ public class SourceCodeCompiler {
|
|||
//通过源文件获取到想要编译的java类源代码迭代器,包括所有的内部类,其中每一个类都是一个JavaFileObjects,也被称为一个汇编单元
|
||||
Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjects(file);
|
||||
//生成编译任务
|
||||
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, Arrays.asList("-d","home/"), null, javaFileObjects);
|
||||
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, Arrays.asList("-d","home/","cp","/home/app.jar"), null, javaFileObjects);
|
||||
//执行编译任务
|
||||
task.call();
|
||||
}catch (Exception e){
|
||||
|
@ -69,4 +70,29 @@ public class SourceCodeCompiler {
|
|||
}
|
||||
}
|
||||
|
||||
// try {
|
||||
// // 初始化 fileManager(此处省略,假设您已有此步骤)
|
||||
//
|
||||
// // 创建一个包含所有依赖 JAR 文件的类路径列表
|
||||
// List<String> classpath = Arrays.asList(
|
||||
// "/home/app.jar"
|
||||
// );
|
||||
//
|
||||
// // 通过源文件获取到想要编译的 JavaFileObjects
|
||||
// Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(file));
|
||||
//
|
||||
// // 生成编译任务,包含类路径
|
||||
// JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null,
|
||||
// Collections.singletonList("-d"), null, classpath, javaFileObjects);
|
||||
//
|
||||
// // 执行编译任务
|
||||
// boolean success = task.call();
|
||||
// if (!success) {
|
||||
// throw new RuntimeException("Compilation failed");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// // 适当的错误处理
|
||||
// e.printStackTrace(); // 或使用日志记录
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue