修改容器部路径
parent
00e6b576d8
commit
84cd1b3ac2
|
@ -1,62 +1,62 @@
|
|||
//package com.muyu.test;
|
||||
//
|
||||
//import com.muyu.BasicEngine;
|
||||
//import com.muyu.core.domain.DataValue;
|
||||
//import com.muyu.domain.EngineVersion;
|
||||
//
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.IOException;
|
||||
//import java.lang.reflect.InvocationTargetException;
|
||||
//import java.net.URL;
|
||||
//import java.nio.file.Path;
|
||||
//import java.nio.file.Paths;
|
||||
//import java.util.Map;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
//
|
||||
//public class RuleTest {
|
||||
// static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// //外部类文件路径
|
||||
// public static final String engineWorkSourcePath = "/home/lib/";
|
||||
// public static final String className = "com.muyu.abstracts.generate.";
|
||||
//
|
||||
// public static void test(EngineVersion engineVersion) {
|
||||
// try {
|
||||
// //外部类文件路径
|
||||
// String externalClassFilePath =
|
||||
// engineWorkSourcePath + "/com/muyu/abstracts/" + engineVersion.getName() + ".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 + engineVersion.getName());
|
||||
// Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
// engineMap.put(engineVersion.getName(), (BasicEngine<DataValue>) instance);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } catch (InvocationTargetException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } catch (InstantiationException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } catch (IllegalAccessException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } catch (NoSuchMethodException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// DataValue dataValue = DataValue.builder()
|
||||
// .type("String")
|
||||
// .label("手机号")
|
||||
// .key("phone")
|
||||
// .value("张三")
|
||||
// .build();
|
||||
//
|
||||
// BasicEngine<DataValue> engine = engineMap.get(engineVersion.getName());
|
||||
// engine.set(dataValue);
|
||||
// engine.execution();
|
||||
// }
|
||||
//
|
||||
//}
|
||||
package com.muyu.test;
|
||||
|
||||
import com.muyu.BasicEngine;
|
||||
import com.muyu.core.domain.DataValue;
|
||||
import com.muyu.domain.EngineVersion;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
public class RuleTest {
|
||||
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
|
||||
//外部类文件路径
|
||||
public static final String engineWorkSourcePath = "/home/lib/";
|
||||
public static final String className = "com.muyu.abstracts.generate.";
|
||||
|
||||
public static void test(EngineVersion engineVersion) {
|
||||
try {
|
||||
//外部类文件路径
|
||||
String externalClassFilePath =
|
||||
engineWorkSourcePath + "/com/muyu/abstracts/" + engineVersion.getName() + ".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 + engineVersion.getName());
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
engineMap.put(engineVersion.getName(), (BasicEngine<DataValue>) instance);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
DataValue dataValue = DataValue.builder()
|
||||
.type("String")
|
||||
.label("手机号")
|
||||
.key("phone")
|
||||
.value("张三")
|
||||
.build();
|
||||
|
||||
BasicEngine<DataValue> engine = engineMap.get(engineVersion.getName());
|
||||
engine.set(dataValue);
|
||||
engine.execution();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue