- Standalone server
There is no installation procedure for Jetty. Just unzip.
Runjava -jar start.jar
If success
INFO:oejs.Server:main: Started @11245ms
By default, Jetty runs on port 8080. To change port open start.ini and change the line
## Connector port to listen on jetty.http.port=8070
and restart Jetty.
To deploy a app copy *.war file to webapps folder and open page byhttp://localhost:8070/name_of_war_file
To change WebApps folder you need to edit start.ini file
# Monitored directory name (relative to $jetty.base) # jetty.deploy.monitoredDir=webapps
- Embedded server
- Maven dependencies
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> <version>9.2.11.v20150529</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlet</artifactId> <version>9.2.11.v20150529</version> </dependency>
-
Develop app
import org.eclipse.jetty.server.*; import org.eclipse.jetty.servlet.*; import java.io.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpStatus; public class jmain { public static void Main(String[] args) { Server sever = new Server(7077); ServletContextHandler handler = new ServletContextHandler(sever, "/example"); handler.addServlet(ExampleServlet.class, "/"); sever.start(); } public class ExampleServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpStatus.OK_200); resp.getWriter().println("EmbeddedJetty"); } } }
- Maven dependencies