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;
}
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;
}
Aggregations