mebyinevere
New Member
so I am trying to setup an embedded jetty 9 server. However when I try:\[quote\] mvn clean compile exec:java\[/quote\]The execution halts at : \[quote\] INFOejs.Server:com.main.SimpleServer.main(): jetty-9.0.0.RC2\[/quote\]After a while I get exceptions like:\[quote\] WARNejuc.AbstractLifeCycle:com.main.SimpleServer.main(): FAILED org.eclipse.jetty.io.SelectorManager$ManagedSelector@45a0110e keys=-1 selected=-1: java.io.IOException: Unable to establish loopback connection java.io.IOException: Unable to establish loopback connection java.net.ConnectException: Connection refused: connect\[/quote\]My code looks like this:\[code\]public class HelloHandler extends AbstractHandler { final String _greeting; final String _body; public HelloHandler() { _greeting = "Hello World"; _body = null; } public HelloHandler(String greeting) { _greeting = greeting; _body = null; } public HelloHandler(String greeting, String body) { _greeting = greeting; _body = body; } public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); response.getWriter().println("<h1>" + _greeting + "</h1>"); if (_body != null) response.getWriter().println(_body); }}\[/code\]and \[code\]public class SimpleServer { public static void main(String[] args) throws Exception { Server server = new Server(8080); server.setHandler(new HelloHandler()); server.start(); server.join(); }}\[/code\]my pom.xml looks like:\[code\]<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>TestJetty</groupId> <artifactId>TestJetty</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <jettyVersion>9.0.0.RC2</jettyVersion> </properties> <dependencies> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> <version>${jettyVersion}</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-websocket</artifactId> <version>7.4.4.v20110707</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-util</artifactId> <version>${jettyVersion}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>3.0-alpha-1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>${jettyVersion}</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1</version> <executions> <execution><goals><goal>java</goal></goals></execution> </executions> <configuration> <mainClass>com.main.SimpleServer</mainClass> </configuration> </plugin> </plugins> </build></project>\[/code\]