RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
return factory.getScriptEngine(createSession(servletContext));
}
public static Session createSession(ServletContext servletContext) {
FileSystemManager fileSystemManager;
try {
fileSystemManager = createFileSystemManager(servletContext);
} catch (FileSystemException e) {
LOG.log(Level.SEVERE, "Failed to initialize VFS file system manager", e);
throw new RuntimeException(e);
}
try {
// initialize our master context here; a fresh but shallow copy will
// be forked on each incoming request
Session session = new SessionBuilder()
.withFileSystemManager(fileSystemManager)
.withDefaultPackages()
.build();
session.setWorkingDirectory(fileSystemManager.resolveFile("file:///"));
return session;
} catch (IOException e) {
LOG.log(Level.SEVERE, "Failed to initialize master context", e);
throw new RuntimeException(e);