Changes
parent
ccdda9a532
commit
f77c58500f
|
@ -1,17 +1,17 @@
|
||||||
//package rule.data.engine.basic;
|
package rule.data.engine.basic;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName BasicEngin
|
* @ClassName BasicEngin
|
||||||
// * @Description 规则引擎基准
|
* @Description 规则引擎基准
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/29 14:28
|
* @Date 2024/8/29 14:28
|
||||||
// */
|
*/
|
||||||
//public interface BasicEngine<V> {
|
public interface BasicEngine<V> {
|
||||||
// public void set(V dataValue);
|
public void set(V dataValue);
|
||||||
//
|
|
||||||
// public V get();
|
public V get();
|
||||||
//
|
|
||||||
// public void remove();
|
public void remove();
|
||||||
//
|
|
||||||
// public void execution();
|
public void execution();
|
||||||
//}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package rule.data.engine.basic.abstracts;
|
||||||
|
|
||||||
|
import rule.data.engine.basic.BasicEngine;
|
||||||
|
import rule.data.engine.basic.handler.DataEngineValueHandler;
|
||||||
|
import rule.domain.DataValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName DataEngineRecordActuator
|
||||||
|
* @Description 描述
|
||||||
|
* @Author Chen
|
||||||
|
* @Date 2024/9/3 10:18
|
||||||
|
*/
|
||||||
|
public abstract class DataEngineRecordActuator implements BasicEngine<DataValue> {
|
||||||
|
@Override
|
||||||
|
public void set(DataValue dataValue) {
|
||||||
|
DataEngineValueHandler.set(dataValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataValue get() {
|
||||||
|
return DataEngineValueHandler.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execution() {
|
||||||
|
this.run();
|
||||||
|
this.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void run();
|
||||||
|
}
|
|
@ -1,22 +1,22 @@
|
||||||
//package rule.data.engine.basic.abstracts;
|
package rule.data.engine.basic.abstracts;
|
||||||
//
|
|
||||||
//
|
|
||||||
//import rule.data.engine.basic.BasicEngine;
|
import rule.data.engine.basic.BasicEngine;
|
||||||
//import rule.data.engine.basic.handler.DataEngineHandler;
|
import rule.data.engine.basic.handler.DataEngineHandler;
|
||||||
//import rule.domain.DataValue;
|
import rule.domain.DataValue;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName DataEngineValueActuator
|
* @ClassName DataEngineValueActuator
|
||||||
// * @Description 数据值处理对象
|
* @Description 数据值处理对象
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/29 16:10
|
* @Date 2024/8/29 16:10
|
||||||
// */
|
*/
|
||||||
//public abstract class DataEngineRowActuator implements BasicEngine<DataValue[]> {
|
public abstract class DataEngineRowActuator implements BasicEngine<DataValue[]> {
|
||||||
// public void set(DataValue[] dataValue) {
|
public void set(DataValue[] dataValue) {
|
||||||
// DataEngineHandler.set(dataValue);
|
DataEngineHandler.set(dataValue);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public DataValue[] get() {
|
public DataValue[] get() {
|
||||||
// return DataEngineHandler.get();
|
return DataEngineHandler.get();
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
|
@ -1,33 +1,32 @@
|
||||||
//package rule.data.engine.basic.abstracts;
|
package rule.data.engine.basic.abstracts;
|
||||||
//
|
|
||||||
//
|
|
||||||
//import rule.data.engine.basic.BasicEngine;
|
import rule.data.engine.basic.BasicEngine;
|
||||||
//import rule.data.engine.basic.handler.DataEngineValueHandler;
|
import rule.data.engine.basic.handler.DataEngineValueHandler;
|
||||||
//import rule.domain.DataValue;
|
import rule.domain.DataValue;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName DataEngineValueActuator
|
* @ClassName DataEngineValueActuator
|
||||||
// * @Description 数据值处理对象
|
* @Description 数据值处理对象
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/29 16:10
|
* @Date 2024/8/29 16:10
|
||||||
// */
|
*/
|
||||||
//public abstract class DataEngineValueActuator implements BasicEngine<DataValue> {
|
public abstract class DataEngineValueActuator implements BasicEngine<DataValue> {
|
||||||
// @Override
|
@Override
|
||||||
// public void set(DataValue dataValue) {
|
public void set(DataValue dataValue) {
|
||||||
// DataEngineValueHandler.set(dataValue);
|
DataEngineValueHandler.set(dataValue);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public DataValue get() {
|
public DataValue get() {
|
||||||
// return DataEngineValueHandler.get();
|
return DataEngineValueHandler.get();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void execution() {
|
public void execution() {
|
||||||
// this.run();
|
this.run();
|
||||||
// this.remove();
|
this.remove();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//
|
public abstract void run();
|
||||||
// public abstract void run();
|
}
|
||||||
//}
|
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
//package rule.data.engine.basic.handler;
|
package rule.data.engine.basic.handler;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName DataEngineHandler
|
* @ClassName DataEngineHandler
|
||||||
// * @Description 规则引擎作用域
|
* @Description 规则引擎作用域
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/29 14:35
|
* @Date 2024/8/29 14:35
|
||||||
// */
|
*/
|
||||||
//public class DataEngineHandler {
|
public class DataEngineHandler {
|
||||||
// private static final ThreadLocal<Object> dataEngineHandler = new ThreadLocal<>();
|
private static final ThreadLocal<Object> dataEngineHandler = new ThreadLocal<>();
|
||||||
//
|
|
||||||
// public static void set(final Object handler) {
|
public static void set(final Object handler) {
|
||||||
// dataEngineHandler.set(handler);
|
dataEngineHandler.set(handler);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static <T> T get() {
|
public static <T> T get() {
|
||||||
// return (T) dataEngineHandler.get();
|
return (T) dataEngineHandler.get();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static void remove() {
|
public static void remove() {
|
||||||
// dataEngineHandler.remove();
|
dataEngineHandler.remove();
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
//package rule.data.engine.basic.handler;
|
package rule.data.engine.basic.handler;
|
||||||
//
|
|
||||||
//import rule.domain.DataValue;
|
import rule.domain.DataValue;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName DataEngineValueHandler
|
* @ClassName DataEngineValueHandler
|
||||||
// * @Description 数据值作用域 数据记录
|
* @Description 数据值作用域 数据记录
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/29 14:41
|
* @Date 2024/8/29 14:41
|
||||||
// */
|
*/
|
||||||
//public class DataEngineRowHandler {
|
public class DataEngineRowHandler {
|
||||||
// public static void set(DataValue[] dataValue) {
|
public static void set(DataValue[] dataValue) {
|
||||||
// DataEngineHandler.set(dataValue);
|
DataEngineHandler.set(dataValue);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public DataValue[] get() {
|
public DataValue[] get() {
|
||||||
// return DataEngineHandler.get();
|
return DataEngineHandler.get();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
//package rule.data.engine.basic.handler;
|
package rule.data.engine.basic.handler;
|
||||||
//
|
|
||||||
//import com.muyu.common.core.text.Convert;
|
import com.muyu.common.core.text.Convert;
|
||||||
//import rule.domain.DataValue;
|
import rule.domain.DataValue;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName DataEngineValueHandler
|
* @ClassName DataEngineValueHandler
|
||||||
// * @Description 数据值作用域
|
* @Description 数据值作用域
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/29 14:41
|
* @Date 2024/8/29 14:41
|
||||||
// */
|
*/
|
||||||
//public class DataEngineValueHandler {
|
public class DataEngineValueHandler {
|
||||||
// public static void set(DataValue dataValue) {
|
public static void set(DataValue dataValue) {
|
||||||
// DataEngineHandler.set(dataValue);
|
DataEngineHandler.set(dataValue);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static DataValue get() {
|
public static DataValue get() {
|
||||||
// return DataEngineHandler.get();
|
return DataEngineHandler.get();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static void remove() {
|
public static void remove() {
|
||||||
// DataEngineHandler.remove();
|
DataEngineHandler.remove();
|
||||||
// }
|
}
|
||||||
// public static Object getValue() {
|
public static Object getValue() {
|
||||||
// return get().getValue();
|
return get().getValue();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static Integer getIntegerValue() {
|
public static Integer getIntegerValue() {
|
||||||
// return Convert.toInt(getValue(), null);
|
return Convert.toInt(getValue(), null);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
//package rule.data.engine.service;
|
package rule.data.engine.service;
|
||||||
//
|
|
||||||
//import rule.data.engine.basic.abstracts.DataEngineValueActuator;
|
import rule.data.engine.basic.abstracts.DataEngineValueActuator;
|
||||||
//import rule.domain.DataValue;
|
import rule.domain.DataValue;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName ENGINE_VALUE_JDIE3456711
|
* @ClassName ENGINE_VALUE_JDIE3456711
|
||||||
// * @Description 判空
|
* @Description 判空
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/29 16:26
|
* @Date 2024/8/29 16:26
|
||||||
// */
|
*/
|
||||||
//public class ENGINE_VALUE_JDIE3456711_V1 extends DataEngineValueActuator {
|
public class ENGINE_VALUE_JDIE3456711_V1 extends DataEngineValueActuator {
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void run() {
|
public void run() {
|
||||||
// DataValue dataValue = get();
|
DataValue dataValue = get();
|
||||||
// if (dataValue.getValue()==null){
|
if (dataValue.getValue()==null){
|
||||||
// System.out.println("数据为空,需要丢弃");
|
System.out.println("数据为空,需要丢弃");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void remove() {
|
public void remove() {
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
|
@ -1,27 +1,25 @@
|
||||||
//package rule.domain;
|
package rule.domain;
|
||||||
//
|
|
||||||
//import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
//import lombok.Builder;
|
import lombok.Builder;
|
||||||
//import lombok.Data;
|
import lombok.Data;
|
||||||
//import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
//
|
|
||||||
//import java.net.SocketOption;
|
import java.net.SocketOption;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName DataValue
|
* @ClassName DataValue
|
||||||
// * @Description 描述
|
* @Description 描述
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/29 15:05
|
* @Date 2024/8/29 15:05
|
||||||
// */
|
*/
|
||||||
//@Data
|
@Data
|
||||||
//@Builder
|
@Builder
|
||||||
//@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
//@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
//public class DataValue {
|
public class DataValue {
|
||||||
// private Object value;
|
private Object value;
|
||||||
// private String type;
|
private String type;
|
||||||
// private String key;
|
private String key;
|
||||||
// private String label;
|
private String label;
|
||||||
//
|
}
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
//package rule.domain;
|
package rule.domain;
|
||||||
//
|
|
||||||
//import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
//import lombok.Data;
|
import lombok.Data;
|
||||||
//import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @ClassName RuleAll
|
* @ClassName RuleAll
|
||||||
// * @Description 描述
|
* @Description 描述
|
||||||
// * @Author Chen
|
* @Author Chen
|
||||||
// * @Date 2024/8/27 09:04
|
* @Date 2024/8/27 09:04
|
||||||
// */
|
*/
|
||||||
//@Data
|
@Data
|
||||||
//@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
//@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
//public class RuleDescribe {
|
public class RuleDescribe {
|
||||||
// //字段名
|
//字段名
|
||||||
// private String key;
|
private String key;
|
||||||
// private Object value;
|
private Object value;
|
||||||
// //元类型 目标类型 逻辑类型
|
//元类型 目标类型 逻辑类型
|
||||||
// private Object type;
|
private Object type;
|
||||||
// //描述
|
//描述
|
||||||
// private String label;
|
private String label;
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.muyu.common.core.exception.ServiceException;
|
||||||
import com.muyu.rule.compile.SourceCodeCompiler;
|
import com.muyu.rule.compile.SourceCodeCompiler;
|
||||||
import com.muyu.rule.service.RuleEditionService;
|
import com.muyu.rule.service.RuleEditionService;
|
||||||
import com.muyu.rule.test.OSSFileDownload;
|
import com.muyu.rule.test.OSSFileDownload;
|
||||||
|
import com.muyu.rule.test.TestService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -29,6 +30,8 @@ import java.util.List;
|
||||||
public class RuleEditionController {
|
public class RuleEditionController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RuleEditionService ruleEditionService;
|
private RuleEditionService ruleEditionService;
|
||||||
|
@Autowired
|
||||||
|
private TestService testService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 规则版本列表
|
* 规则版本列表
|
||||||
|
@ -63,27 +66,27 @@ public class RuleEditionController {
|
||||||
@Operation(summary = "添加版本", description = "添加版本")
|
@Operation(summary = "添加版本", description = "添加版本")
|
||||||
public Result insert(@RequestBody @Validated RuleEdition ruleEdition) {
|
public Result insert(@RequestBody @Validated RuleEdition ruleEdition) {
|
||||||
|
|
||||||
//java OSS
|
// //java OSS
|
||||||
UploadOss.uploadFiles(ruleEdition.getRuleEngine(), ruleEdition.getRuleKind());
|
// UploadOss.uploadFiles(ruleEdition.getRuleEngine(), ruleEdition.getRuleKind());
|
||||||
|
//
|
||||||
OSSFileDownload.streamingDownload(ruleEdition.getRuleKind());
|
// OSSFileDownload.streamingDownload(ruleEdition.getRuleKind());
|
||||||
|
//
|
||||||
//对路径里的.java文件进行编译
|
// //对路径里的.java文件进行编译
|
||||||
SourceCodeCompiler.javaCompilerPath("/home");
|
// SourceCodeCompiler.javaCompilerPath("/home");
|
||||||
//指定的输出目录
|
// //指定的输出目录
|
||||||
File outputDir = new File("/home");
|
// File outputDir = new File("/home");
|
||||||
//获取输出目录中文件
|
// //获取输出目录中文件
|
||||||
File[] classFiles = outputDir.listFiles();
|
// File[] classFiles = outputDir.listFiles();
|
||||||
if (classFiles != null) {
|
// if (classFiles != null) {
|
||||||
for (File classFile : classFiles) {
|
// for (File classFile : classFiles) {
|
||||||
if (classFile.getName().endsWith(".class")) {
|
// if (classFile.getName().endsWith(".class")) {
|
||||||
log.info("找到class文件 " + classFile.getName());
|
// log.info("找到class文件 " + classFile.getName());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
log.info("没有找到文件");
|
// log.info("没有找到文件");
|
||||||
}
|
// }
|
||||||
|
testService.test();
|
||||||
LambdaQueryWrapper<RuleEdition> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<RuleEdition> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(
|
queryWrapper.eq(
|
||||||
RuleEdition::getRuleKind, ruleEdition.getRuleKind()
|
RuleEdition::getRuleKind, ruleEdition.getRuleKind()
|
||||||
|
@ -178,6 +181,7 @@ public class RuleEditionController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存代码
|
* 保存代码
|
||||||
|
*
|
||||||
* @param ruleEdition
|
* @param ruleEdition
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.muyu.rule.test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class ExternalClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
|
public ExternalClassLoader(URL[] urls) {
|
||||||
|
super(urls, Thread.currentThread().getContextClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> defineClassFromBytes(byte[] classBytes, String className) throws IOException {
|
||||||
|
return super.defineClass(className, classBytes, 0, classBytes.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> loadClassFromPath(Path classFilePath, String className) throws IOException {
|
||||||
|
byte[] classData = Files.readAllBytes(classFilePath);
|
||||||
|
return defineClassFromBytes(classData, className);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
package com.muyu.rule.test;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import rule.data.engine.basic.BasicEngine;
|
||||||
|
import rule.domain.DataValue;
|
||||||
|
|
||||||
|
import javax.tools.JavaCompiler;
|
||||||
|
import javax.tools.ToolProvider;
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TestService {
|
||||||
|
|
||||||
|
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static final String engineWorkSourcePath = "D:\\work\\cc";
|
||||||
|
// public static final String engineWorkClassPath = engineWorkSourcePath;
|
||||||
|
public static final String className = "rule.data.engine.service.ENGINE_VALUE_JDIE3456711_V1";
|
||||||
|
|
||||||
|
|
||||||
|
// package com.muyu.data.engine.service;
|
||||||
|
public static final String code =
|
||||||
|
"""
|
||||||
|
package com.muyu.data.engine.service;
|
||||||
|
|
||||||
|
import com.muyu.data.engine.basic.abstracts.DataEngineValueActuator;
|
||||||
|
import com.muyu.etl.core.domain.DataValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: cc
|
||||||
|
* @date: 2024/9/29
|
||||||
|
* @Description: 判空
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class ENGINE_VALUE_JDIES979972_V2 extends DataEngineValueActuator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run () {
|
||||||
|
DataValue dataValue = get();
|
||||||
|
if (dataValue.getValue() == null){
|
||||||
|
System.out.println("数据为空,需要丢弃");
|
||||||
|
}else{
|
||||||
|
System.out.println("数据非空:"+dataValue.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
FileWriter writer;
|
||||||
|
writer = new FileWriter(engineWorkSourcePath + "\\ENGINE_VALUE_JDIE3456711_V1.java");
|
||||||
|
writer.write(code);
|
||||||
|
writer.flush();
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
// 获取java编译器
|
||||||
|
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||||
|
//
|
||||||
|
InputStream first = null; // 程序的输入 null 用 system.in
|
||||||
|
OutputStream second = null; // 程序的输出 null 用 system.out
|
||||||
|
OutputStream third = null; // 程序的错误输出 .,null 用 system.err
|
||||||
|
// 程序编译参数 注意 我们编译目录是我们的项目目录
|
||||||
|
String[] strings = {"-classpath", engineWorkSourcePath, "-verbose", "-d", engineWorkSourcePath, engineWorkSourcePath + "\\ENGINE_VALUE_JDIE3456711_V1.java"};
|
||||||
|
// 0 表示成功, 其他表示出现了错误
|
||||||
|
System.out.println(Arrays.toString(strings));
|
||||||
|
int i = javaCompiler.run(first, second, third, strings);
|
||||||
|
if (i == 0) {
|
||||||
|
System.out.println("成功");
|
||||||
|
} else {
|
||||||
|
System.out.println("错误");
|
||||||
|
}
|
||||||
|
// 假设这是你的外部类文件路径
|
||||||
|
String externalClassFilePath =
|
||||||
|
engineWorkSourcePath + "\\com\\muyu\\rule\\test\\ENGINE_VALUE_JDIE3456711_V1.class";
|
||||||
|
Path classFilePath = Paths.get(externalClassFilePath);
|
||||||
|
// 获取外部类所在的目录
|
||||||
|
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('\\'));
|
||||||
|
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||||
|
|
||||||
|
// 创建自定义类加载器
|
||||||
|
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||||
|
|
||||||
|
// 加载类
|
||||||
|
// 注意类名必须是完全限定名(包括包名)
|
||||||
|
Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath, className);
|
||||||
|
// Class<?> clazz = customClassLoader.defineClassFromBytes(externalClassBytes);
|
||||||
|
// 创建类的实例
|
||||||
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
engineMap.put("ENGINE_VALUE_JDIE3456711_V1", (BasicEngine<DataValue>) instance);
|
||||||
|
|
||||||
|
} catch (IllegalAccessException | IOException | InstantiationException |
|
||||||
|
NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
DataValue dataValue = DataValue.builder()
|
||||||
|
.type("String")
|
||||||
|
.label("姓名")
|
||||||
|
.key("name")
|
||||||
|
.value("张三")
|
||||||
|
.build();
|
||||||
|
BasicEngine<DataValue> engine = engineMap.get("ENGINE_VALUE_JDIE3456711_V1");
|
||||||
|
engine.set(dataValue);
|
||||||
|
engine.execution();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue