Search in sources :

Example 1 with JavaFile

use of org.glassfish.jersey.examples.reload.compiler.JavaFile in project jersey by jersey.

the class App method getJavaFiles.

private static List<JavaFile> getJavaFiles(File configFile) throws Exception {
    final List<JavaFile> javaFiles = new LinkedList<>();
    try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), "UTF-8"))) {
        while (r.ready()) {
            final String className = r.readLine();
            if (!className.startsWith("#")) {
                javaFiles.add(new JavaFile(className, SRC_MAIN_JAVA));
                LOGGER.info(String.format(" + included class %s.\n", className));
            } else {
                LOGGER.info(String.format(" - ignored class %s\n", className.substring(1)));
            }
        }
    }
    return javaFiles;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) JavaFile(org.glassfish.jersey.examples.reload.compiler.JavaFile) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream)

Example 2 with JavaFile

use of org.glassfish.jersey.examples.reload.compiler.JavaFile in project jersey by jersey.

the class App method createResourceConfig.

private static ResourceConfig createResourceConfig(File configFile) {
    final ResourceConfig rc = new ResourceConfig();
    try {
        final AppClassLoader appClassLoader = new AppClassLoader(Thread.currentThread().getContextClassLoader());
        final List<JavaFile> javaFiles = getJavaFiles(configFile);
        Compiler.compile(appClassLoader, javaFiles);
        for (JavaFile javaFile : javaFiles) {
            try {
                rc.registerClasses(appClassLoader.loadClass(javaFile.getClassName()));
            } catch (final ClassNotFoundException ex) {
                LOGGER.info(String.format(" ! class %s not found.\n", javaFile.getClassName()));
            }
        }
    } catch (final Exception ex) {
        Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
    return rc;
}
Also used : AppClassLoader(org.glassfish.jersey.examples.reload.compiler.AppClassLoader) JavaFile(org.glassfish.jersey.examples.reload.compiler.JavaFile) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) IOException(java.io.IOException)

Aggregations

JavaFile (org.glassfish.jersey.examples.reload.compiler.JavaFile)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 LinkedList (java.util.LinkedList)1 AppClassLoader (org.glassfish.jersey.examples.reload.compiler.AppClassLoader)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1