use of org.eclipse.jetty.servlet.DefaultServlet in project groovity by disney.
the class GroovityStandalone method main.
public static void main(String[] args) {
try {
int port = -1;
int securePort = -1;
String keyStoreLocation = null;
String keyStorePassword = null;
if (args.length > 0) {
port = Integer.parseInt(args[0]);
if (args.length > 1) {
securePort = Integer.parseInt(args[1]);
if (args.length > 2) {
keyStoreLocation = args[2];
if (args.length > 3) {
keyStorePassword = args[3];
} else {
keyStorePassword = "";
}
}
}
}
File workingDirectory = new File("").getAbsoluteFile();
File groovityDirectory = new File(workingDirectory, "groovity");
if (!groovityDirectory.exists() || !groovityDirectory.isDirectory()) {
throw new FileNotFoundException("No directory found at " + groovityDirectory.getAbsolutePath());
}
List<URL> projectClasspathList = new ArrayList<URL>();
File libDirectory = new File(workingDirectory, "lib");
if (libDirectory.exists() && libDirectory.isDirectory()) {
File[] jars = libDirectory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".jar");
}
});
if (jars != null && jars.length > 0) {
for (int i = 0; i < jars.length; i++) {
projectClasspathList.add(jars[i].toURI().toURL());
}
}
}
File resourceDirectory = new File(workingDirectory, "static");
if (!resourceDirectory.exists() || !resourceDirectory.isDirectory()) {
resourceDirectory = null;
}
File jarDirectory = new File(workingDirectory, "target");
if (!jarDirectory.exists() || !jarDirectory.isDirectory()) {
jarDirectory = null;
}
File confDirectory = new File(workingDirectory, "conf");
if (!confDirectory.exists() || !confDirectory.isDirectory()) {
confDirectory = null;
}
URLClassLoader loader = new URLClassLoader(projectClasspathList.toArray(new URL[0]), Thread.currentThread().getContextClassLoader());
GroovityServletContainerBuilder groovityServletContainerBuilder = new GroovityServletContainerBuilder().addSourceLocation(groovityDirectory.toURI(), true).setPort(port).setSecurePort(Integer.valueOf(securePort)).setSecureKeyStoreLocation(keyStoreLocation).setSecureKeyStorePassword(keyStorePassword).setWebappDirectory(workingDirectory).setClassLoader(loader);
if (jarDirectory != null) {
groovityServletContainerBuilder.setJarDirectory(jarDirectory);
}
if (confDirectory != null) {
groovityServletContainerBuilder.setPropsFile(confDirectory.getAbsolutePath());
}
DefaultServlet resourceServlet = new DefaultServlet();
ServletHolder resourceServletHolder = new ServletHolder(resourceServlet);
GroovityServletContainer container = groovityServletContainerBuilder.build();
WebAppContext context = container.getContext();
context.addServlet(resourceServletHolder, "/static/*");
container.start();
try {
container.enterConsole();
} finally {
container.stop();
}
} catch (Throwable e) {
logger.log(Level.SEVERE, "Error in groovity standalone", e);
}
System.exit(0);
}
Aggregations