修改容器部路径
parent
c941e6bf36
commit
00e6b576d8
|
@ -1,62 +1,62 @@
|
||||||
package com.muyu.test;
|
//package com.muyu.test;
|
||||||
|
//
|
||||||
import com.muyu.BasicEngine;
|
//import com.muyu.BasicEngine;
|
||||||
import com.muyu.core.domain.DataValue;
|
//import com.muyu.core.domain.DataValue;
|
||||||
import com.muyu.domain.EngineVersion;
|
//import com.muyu.domain.EngineVersion;
|
||||||
|
//
|
||||||
|
//
|
||||||
import java.io.File;
|
//import java.io.File;
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
//import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.URL;
|
//import java.net.URL;
|
||||||
import java.nio.file.Path;
|
//import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
//import java.nio.file.Paths;
|
||||||
import java.util.Map;
|
//import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
//import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
//
|
||||||
|
//
|
||||||
public class RuleTest {
|
//public class RuleTest {
|
||||||
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
// static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||||
|
//
|
||||||
//外部类文件路径
|
// //外部类文件路径
|
||||||
public static final String engineWorkSourcePath = "/home/lib/";
|
// public static final String engineWorkSourcePath = "/home/lib/";
|
||||||
public static final String className = "com.muyu.abstracts.generate.";
|
// public static final String className = "com.muyu.abstracts.generate.";
|
||||||
|
//
|
||||||
public static void test(EngineVersion engineVersion) {
|
// public static void test(EngineVersion engineVersion) {
|
||||||
try {
|
// try {
|
||||||
//外部类文件路径
|
// //外部类文件路径
|
||||||
String externalClassFilePath =
|
// String externalClassFilePath =
|
||||||
engineWorkSourcePath + "/com/muyu/abstracts/" + engineVersion.getName() + ".class";
|
// engineWorkSourcePath + "/com/muyu/abstracts/" + engineVersion.getName() + ".class";
|
||||||
Path classFilePath = Paths.get(externalClassFilePath);
|
// Path classFilePath = Paths.get(externalClassFilePath);
|
||||||
//获取外部类所在的目录
|
// //获取外部类所在的目录
|
||||||
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
// String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||||
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
// URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||||
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
// ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||||
//加载类 全限定名
|
// //加载类 全限定名
|
||||||
Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath, className + engineVersion.getName());
|
// Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath, className + engineVersion.getName());
|
||||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
// Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
engineMap.put(engineVersion.getName(), (BasicEngine<DataValue>) instance);
|
// engineMap.put(engineVersion.getName(), (BasicEngine<DataValue>) instance);
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
} catch (InvocationTargetException e) {
|
// } catch (InvocationTargetException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
} catch (InstantiationException e) {
|
// } catch (InstantiationException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
} catch (IllegalAccessException e) {
|
// } catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
} catch (NoSuchMethodException e) {
|
// } catch (NoSuchMethodException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
DataValue dataValue = DataValue.builder()
|
// DataValue dataValue = DataValue.builder()
|
||||||
.type("String")
|
// .type("String")
|
||||||
.label("手机号")
|
// .label("手机号")
|
||||||
.key("phone")
|
// .key("phone")
|
||||||
.value("张三")
|
// .value("张三")
|
||||||
.build();
|
// .build();
|
||||||
|
//
|
||||||
BasicEngine<DataValue> engine = engineMap.get(engineVersion.getName());
|
// BasicEngine<DataValue> engine = engineMap.get(engineVersion.getName());
|
||||||
engine.set(dataValue);
|
// engine.set(dataValue);
|
||||||
engine.execution();
|
// engine.execution();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|
Loading…
Reference in New Issue