use of io.vertx.core.impl.verticle.CompilingClassLoader in project vert.x by eclipse.
the class DeploymentTest method createClassOutsideClasspath.
private String createClassOutsideClasspath(String className) throws Exception {
File dir = Files.createTempDirectory("vertx").toFile();
dir.deleteOnExit();
File source = new File(dir, className + ".java");
Files.write(source.toPath(), ("public class " + className + " extends io.vertx.core.AbstractVerticle {} ").getBytes());
URLClassLoader loader = new URLClassLoader(new URL[] { dir.toURI().toURL() }, Thread.currentThread().getContextClassLoader());
CompilingClassLoader compilingClassLoader = new CompilingClassLoader(loader, className + ".java");
compilingClassLoader.loadClass(className);
byte[] bytes = compilingClassLoader.getClassBytes(className);
assertNotNull(bytes);
File classFile = new File(dir, className + ".class");
Files.write(classFile.toPath(), bytes);
return dir.getAbsolutePath();
}
use of io.vertx.core.impl.verticle.CompilingClassLoader in project vert.x by eclipse.
the class JavaVerticleFactory method createVerticle.
@Override
public Verticle createVerticle(String verticleName, ClassLoader classLoader) throws Exception {
verticleName = VerticleFactory.removePrefix(verticleName);
Class clazz;
if (verticleName.endsWith(".java")) {
CompilingClassLoader compilingLoader = new CompilingClassLoader(classLoader, verticleName);
String className = compilingLoader.resolveMainClassName();
clazz = compilingLoader.loadClass(className);
} else {
clazz = classLoader.loadClass(verticleName);
}
return (Verticle) clazz.newInstance();
}
Aggregations