Я заставил его работать с JavaCompiler и загрузчиком пользовательских классов, как показано ниже.
private Path compileSource(Path javaFile, String contractFileNameWithoutExtension) {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
compiler.run(null, null, null, javaFile.toFile().getAbsolutePath());
return javaFile.getParent().resolve(contractFileNameWithoutExtension+".class");
}
public Class findClass(String name) {
String filePath = sourceCodeLocation +"/"+ name.replace(".", "/")+".class";
byte[] b = loadClassFromFile(filePath);
return defineClass(name, b, 0, b.length);
}
private byte[] loadClassFromFile(String fileName) {
try {
InputStream inputStream = FileUtils.getFileInputStream.apply(fileName);
byte[] buffer;
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
int nextValue = 0;
try {
while ((nextValue = inputStream.read()) != -1) {
byteStream.write(nextValue);
}
} catch (IOException e) {
e.printStackTrace();
}
buffer = byteStream.toByteArray();
return buffer;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}