Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Jason here is what works for me, this is what I use quite often, pom.xml (relevant part) :</p> <pre><code>&lt;dependencies&gt; &lt;!-- Jetty dependencies --&gt; &lt;dependency&gt; &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt; &lt;artifactId&gt;jetty-embedded&lt;/artifactId&gt; &lt;version&gt;6.1.26&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt; &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt; &lt;version&gt;7.0.2.v20100331&lt;/version&gt; &lt;configuration&gt; &lt;webAppConfig&gt; &lt;contextPath&gt;/jetty-example&lt;/contextPath&gt; &lt;descriptor&gt;${basedir}/src/main/webapp/WEB-INF/web.xml&lt;/descriptor&gt; &lt;/webAppConfig&gt; &lt;scanIntervalSeconds&gt;5&lt;/scanIntervalSeconds&gt; &lt;stopPort&gt;9966&lt;/stopPort&gt; &lt;stopKey&gt;foo&lt;/stopKey&gt; &lt;connectors&gt; &lt;connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"&gt; &lt;port&gt;9080&lt;/port&gt; &lt;maxIdleTime&gt;60000&lt;/maxIdleTime&gt; &lt;/connector&gt; &lt;/connectors&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; </code></pre> <p>Here is the web.xml located at the location specified above in webappconfig as descriptor :</p> <pre><code>&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"&gt; &lt;display-name&gt;HelloWorld Application&lt;/display-name&gt; &lt;description&gt; lalala &lt;/description&gt; &lt;servlet&gt; &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;com.mypackage.jetty.Hello&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/hello&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p>And the servlet itself :</p> <pre><code>public final class Hello extends HttpServlet { private static final long serialVersionUID = 903359962771189189L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.println("&lt;html&gt;"); writer.println("&lt;head&gt;"); writer.println("&lt;title&gt;Sample Application Servlet Page&lt;/title&gt;"); writer.println("&lt;/head&gt;"); writer.println("&lt;body bgcolor=white&gt;"); writer.println("&lt;table border=\"0\" cellpadding=\"10\"&gt;"); writer.println("&lt;tr&gt;"); writer.println("&lt;td&gt;"); writer.println("&lt;/td&gt;"); writer.println("&lt;td&gt;"); writer.println("&lt;h1&gt;W00w I totally work&lt;/h1&gt;"); writer.println("&lt;/td&gt;"); writer.println("&lt;/tr&gt;"); writer.println("&lt;/table&gt;"); writer.println("&lt;/body&gt;"); writer.println("&lt;/html&gt;"); } } </code></pre> <p>You can run the server by running <code>mvn jetty:run</code> and check it at <code>http://localhost:9080/jetty-example/hello</code></p> <p>Additionally you can add execution to the plugin part and start the jetty when you finnish building your project. Without having to manually <code>mvn jetty:run</code> every time.</p> <pre><code>&lt;executions&gt; &lt;execution&gt; &lt;id&gt;start-jetty&lt;/id&gt; &lt;phase&gt;pre-integration-test&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;run&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;daemon&gt;true&lt;/daemon&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;execution&gt; &lt;id&gt;stop-jetty&lt;/id&gt; &lt;phase&gt;post-integration-test&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;stop&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; </code></pre> <p>You can additionally add the jetty configuration file, which I use for database(for different environments). You would add the file location in the <code>webAppConfig</code> of your jetty plugin like this :</p> <pre><code>&lt;webAppConfig&gt; &lt;contextPath&gt;/my-tool&lt;/contextPath&gt; &lt;descriptor&gt;${basedir}/src/main/webapp/WEB-INF/jetty/web.xml &lt;/descriptor&gt; &lt;jettyEnvXml&gt;${basedir}/src/main/webapp/WEB-INF/jetty/jetty-env.xml &lt;/jettyEnvXml&gt; &lt;/webAppConfig&gt; </code></pre> <p>And sample content of the jetty-env.xml :</p> <pre><code>&lt;!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"[]&gt; &lt;Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"&gt; &lt;!-- PRIMARY DATABASE --&gt; &lt;New id="devDS" class="org.eclipse.jetty.plus.jndi.Resource"&gt; &lt;Arg&gt;primaryDS&lt;/Arg&gt; &lt;Arg&gt; &lt;!-- i.e. Postgress --&gt; &lt;New class="org.postgresql.ds.PGSimpleDataSource"&gt; &lt;Set name="User"&gt;myuser&lt;/Set&gt; &lt;Set name="Password"&gt;password&lt;/Set&gt; &lt;Set name="DatabaseName"&gt;database&lt;/Set&gt; &lt;Set name="ServerName"&gt;database.stackoverflow.com&lt;/Set&gt; &lt;Set name="PortNumber"&gt;5432&lt;/Set&gt; &lt;/New&gt; &lt;/Arg&gt; &lt;/New&gt; &lt;!-- BACKUP DATABASE &lt;New id="devDS" class="org.eclipse.jetty.plus.jndi.Resource"&gt; &lt;Arg&gt;backupDS&lt;/Arg&gt; &lt;Arg&gt; ..... &lt;/Arg&gt; --&gt; &lt;/Configure&gt; </code></pre> <p>You should be good with this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload