feat():测试
parent
602de88ba3
commit
f20a6c393f
|
@ -46,7 +46,7 @@ public class OSSFileLoad {
|
||||||
return Result.error("预下载文件不存在");
|
return Result.error("预下载文件不存在");
|
||||||
}
|
}
|
||||||
// 本地文件下载路径
|
// 本地文件下载路径
|
||||||
String localPath = "home/app.jar/"+fileName;
|
String localPath = "home/"+fileName;
|
||||||
// ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, filePath + fileName), new File(localPath));
|
// ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, filePath + fileName), new File(localPath));
|
||||||
// System.out.println(object);
|
// System.out.println(object);
|
||||||
//
|
//
|
||||||
|
@ -76,10 +76,10 @@ public class OSSFileLoad {
|
||||||
}
|
}
|
||||||
|
|
||||||
//对路径里的.java文件进行编译
|
//对路径里的.java文件进行编译
|
||||||
SourceCodeCompiler.javaCompilerPath("/home/app.jar/");
|
SourceCodeCompiler.javaCompilerPath("/home/");
|
||||||
System.out.println("第一步");
|
|
||||||
File outputDir = new File("home/app.jar/"); // 或者是你指定的其他输出目录
|
|
||||||
System.out.println("第一步");
|
System.out.println("第一步");
|
||||||
|
File outputDir = new File("home/"); // 或者是你指定的其他输出目录
|
||||||
|
System.out.println("第二步");
|
||||||
File[] classFiles = outputDir.listFiles(); // 获取输出目录中的所有文件
|
File[] classFiles = outputDir.listFiles(); // 获取输出目录中的所有文件
|
||||||
System.out.println("第三步");
|
System.out.println("第三步");
|
||||||
if (classFiles != null) {
|
if (classFiles != null) {
|
||||||
|
|
|
@ -9,12 +9,6 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName JavaCodeScan
|
|
||||||
* @Description 描述
|
|
||||||
* @Author YiBo.Liu
|
|
||||||
* @Date 2024/8/23 10:36
|
|
||||||
*/
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class JavaCodeScan extends ClassLoader{
|
public class JavaCodeScan extends ClassLoader{
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,6 @@ import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName SourceCodeCompiler
|
|
||||||
* @Description 描述
|
|
||||||
* @Author YiBo.Liu
|
|
||||||
* @Date 2024/8/23 10:35
|
|
||||||
*/
|
|
||||||
public class SourceCodeCompiler {
|
public class SourceCodeCompiler {
|
||||||
|
|
||||||
private static final Logger log = LogManager.getLogger(SourceCodeCompiler.class.getName());
|
private static final Logger log = LogManager.getLogger(SourceCodeCompiler.class.getName());
|
||||||
|
@ -37,11 +31,14 @@ public class SourceCodeCompiler {
|
||||||
* @param path 文件夹路径
|
* @param path 文件夹路径
|
||||||
*/
|
*/
|
||||||
public static void javaCompilerPath(String path){
|
public static void javaCompilerPath(String path){
|
||||||
List<File> files = JavaCodeScan.getJavaFiles(path);
|
try {
|
||||||
File[] array = files.toArray(new File[files.size()]);
|
List<File> files = JavaCodeScan.getJavaFiles(path);
|
||||||
javaCompiler(array);
|
System.out.println(files);
|
||||||
|
File[] array = files.toArray(new File[files.size()]);
|
||||||
|
javaCompiler(array);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,12 +58,16 @@ public class SourceCodeCompiler {
|
||||||
* @param file
|
* @param file
|
||||||
*/
|
*/
|
||||||
public static void javaCompiler(File...file){
|
public static void javaCompiler(File...file){
|
||||||
//通过源文件获取到想要编译的java类源代码迭代器,包括所有的内部类,其中每一个类都是一个JavaFileObjects,也被称为一个汇编单元
|
try {
|
||||||
Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjects(file);
|
//通过源文件获取到想要编译的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/"), null, javaFileObjects);
|
||||||
task.call();
|
//执行编译任务
|
||||||
|
task.call();
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.muyu;
|
||||||
|
|
||||||
|
import com.muyu.util.SourceCodeCompiler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu
|
||||||
|
* @Project:cloud-rule
|
||||||
|
* @name:test
|
||||||
|
* @Date:2024/9/2 上午9:01
|
||||||
|
*/
|
||||||
|
public class test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
//对路径里的.java文件进行编译
|
||||||
|
System.out.println("第一步");
|
||||||
|
SourceCodeCompiler.javaCompilerPath("C:\\Users\\13636\\Desktop\\test\\");
|
||||||
|
System.out.println("第二步");
|
||||||
|
File outputDir = new File("C:\\Users\\13636\\Desktop\\test\\com\\muyu\\generate\\");
|
||||||
|
System.out.println(outputDir);// 指定的其他输出目录
|
||||||
|
System.out.println("第三步");
|
||||||
|
File[] classFiles = outputDir.listFiles(); // 获取输出目录中的所有文件
|
||||||
|
System.out.println(classFiles.length);
|
||||||
|
if (classFiles != null) {
|
||||||
|
for (File classFile : classFiles) {
|
||||||
|
if (classFile.getName().endsWith(".class")) {
|
||||||
|
System.out.println("找到class文件 " + classFile.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue