Search in sources :

Example 1 with CompilingClassLoader

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();
}
Also used : CompilingClassLoader(io.vertx.core.impl.verticle.CompilingClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File)

Example 2 with CompilingClassLoader

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();
}
Also used : Verticle(io.vertx.core.Verticle) CompilingClassLoader(io.vertx.core.impl.verticle.CompilingClassLoader)

Aggregations

CompilingClassLoader (io.vertx.core.impl.verticle.CompilingClassLoader)2 Verticle (io.vertx.core.Verticle)1 File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1