Skip to content

Instantly share code, notes, and snippets.

@ezhov-da
Last active March 10, 2019 12:22
Show Gist options
  • Save ezhov-da/ec1299d06f816b773b421a842f44a4af to your computer and use it in GitHub Desktop.
Save ezhov-da/ec1299d06f816b773b421a842f44a4af to your computer and use it in GitHub Desktop.
java jetty
[code:]XML[:code]
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.1.v20170120</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-servlet -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.1.v20170120</version>
</dependency>
[/code]
[code:]JAVA[:code]
public class App
{
public static void main( String[] args )
{
int port = 8111;
Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS );
context.setContextPath( "/" );
context.addServlet(new ServletHolder( new SrvltIndex( ) ),"/");
context.addServlet(new ServletHolder( new SrvltOne( ) ),"/o");
context.addServlet(new ServletHolder( new SrvltTwo( ) ),"/t");
HandlerList handlers = new HandlerList( );
handlers.setHandlers( new Handler[] { context } );
server.setHandler( handlers );
try {
server.start();
System.out.println("Listening port : " + port );
server.join();
} catch (Exception e) {
System.out.println("Error.");
e.printStackTrace();
}
}
}
[/code]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment