Skip to content

Instantly share code, notes, and snippets.

@lindenb
Last active December 3, 2015 00:07
Show Gist options
  • Save lindenb/1fa88442f829d197705a to your computer and use it in GitHub Desktop.
Save lindenb/1fa88442f829d197705a to your computer and use it in GitHub Desktop.
Setting up a jetty server for https://www.biostars.org/p/168197/
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.servlet.*;
public class BamServer {
public static void main(String[] args) throws Exception {
Server jettyServer = new Server(8080);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
DefaultServlet servlet= new DefaultServlet();
ServletHolder holderPwd = new ServletHolder("default", servlet);
holderPwd.setInitParameter("resourceBase", "/home/user/path/to/directory");
context.addServlet(holderPwd, "/*");
jettyServer.setHandler(context);
try {
jettyServer.start();
jettyServer.join();
} finally {
jettyServer.destroy();
}
}
}
$ curl -s -r 10-100 "http://localhost:8080/blastn.xml"
ion="1.0"?>
<!DOCTYPE BlastOutput PUBLIC "-//NCBI//NCBI BlastOutput/EN" "http://www.ncbi.nl
lib.dir=lib
jetty.jars=$(lib.dir)/org/eclipse/jetty/jetty-servlet/9.3.6.v20151106/jetty-servlet-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-server/9.3.6.v20151106/jetty-server-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-io/9.3.6.v20151106/jetty-io-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-security/9.3.6.v20151106/jetty-security-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-util/9.3.6.v20151106/jetty-util-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-http/9.3.6.v20151106/jetty-http-9.3.6.v20151106.jar:$(lib.dir)/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar
all: $(subst :, ,${jetty.jars}) BamServer.java
javac -cp ${jetty.jars} BamServer.java
java -cp ${jetty.jars}:. BamServer
$(subst :, ,${jetty.jars}) :
mkdir -p $(dir $@) && wget -O "$@" "http://central.maven.org/maven2/$(patsubst ${lib.dir}/%,%,$@)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment