質問

How I can enable a jetty embedded server in my wicket application that could to allow me to control my application in a deamon way like above:

java -jar wicket_jetty_webapp.jar start
java -jar wicket_jetty_webapp.jar stop
java -jar wicket_jetty_webapp.jar status

Rundeck application, that uses Grails framework, works in this way. The google refine use the same approach. For me it's awesome to use a web app with the same way.

Someone know a good resources or articles that explain this subject, with maven?

Also, it's possible to configure jetty to offer a live update feature like play framework offers or like using JRebel?

役に立ちましたか?

解決

If use maven you can help some like:

POM:

  <!--  JETTY DEPENDENCIES FOR TESTING  -->       <dependency>
      <groupId>org.eclipse.jetty.aggregate</groupId>
      <artifactId>jetty-all-server</artifactId>
      <version>${jetty.version}</version>             <scope>provided</scope>
  </dependency>   </dependencies>     <build>         <resources>             <resource>
          <filtering>false</filtering>
          <directory>src/main/resources</directory>           </resource>             <resource>
          <filtering>false</filtering>
          <directory>src/main/java</directory>
          <includes>
              <include>**</include>
          </includes>
          <excludes>
              <exclude>**/*.java</exclude>
          </excludes>             </resource>         </resources>        <testResources>             <testResource>
          <filtering>false</filtering>
          <directory>src/test/resources</directory>           </testResource>             <testResource>
          <filtering>false</filtering>
          <directory>src/test/java</directory>
          <includes>
              <include>**</include>
          </includes>
          <excludes>
              <exclude>**/*.java</exclude>
          </excludes>             </testResource>         </testResources>        <plugins>           <plugin>
          <inherited>true</inherited>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.5.1</version>
          <configuration>
              <source>1.6</source>
              <target>1.6</target>
              <encoding>UTF-8</encoding>
              <showWarnings>true</showWarnings>
              <showDeprecation>true</showDeprecation>
          </configuration>            </plugin>           <plugin>
          <groupId>org.mortbay.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <version>${jetty.version}</version>
          <configuration>
              <connectors>
                  <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                      <port>8080</port>
                      <maxIdleTime>3600000</maxIdleTime>
                  </connector>
                  <connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector">
                      <port>8443</port>
                      <maxIdleTime>3600000</maxIdleTime>
                      <keystore>${project.build.directory}/test-classes/keystore</keystore>
                      <password>wicket</password>
                      <keyPassword>wicket</keyPassword>
                  </connector>
              </connectors>
          </configuration>            </plugin>           <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-eclipse-plugin</artifactId>
          <version>2.9</version>
          <configuration>
              <downloadSources>true</downloadSources>
          </configuration>            </plugin>       </plugins>

Main.class:

public class Main {

    public static void main(String[] args) throws Exception {
        int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

        Server server = new Server();
        SocketConnector connector = new SocketConnector();

        // Set some timeout options to make debugging easier.
        connector.setMaxIdleTime(timeout);
        connector.setSoLingerTime(-1);
        connector.setPort(8080);
        server.addConnector(connector);

        Resource keystore = Resource.newClassPathResource("/keystore");
        if (keystore != null && keystore.exists()) {
            // if a keystore for a SSL certificate is available, start a SSL
            // connector on port 8443.
            // By default, the quickstart comes with a Apache Wicket Quickstart
            // Certificate that expires about half way september 2021. Do not
            // use this certificate anywhere important as the passwords are
            // available in the source.

            connector.setConfidentialPort(8443);

            SslContextFactory factory = new SslContextFactory();
            factory.setKeyStoreResource(keystore);
            factory.setKeyStorePassword("wicket");
            factory.setTrustStoreResource(keystore);
            factory.setKeyManagerPassword("wicket");
            SslSocketConnector sslConnector = new SslSocketConnector(factory);
            sslConnector.setMaxIdleTime(timeout);
            sslConnector.setPort(8443);
            sslConnector.setAcceptors(4);
            server.addConnector(sslConnector);

            System.out.println("SSL access to the quickstart has been enabled on port 8443");
            System.out.println("You can access the application using SSL on https://localhost:8443");
            System.out.println();
        }

        WebAppContext bb = new WebAppContext();
        bb.setServer(server);
        bb.setContextPath("/");
        bb.setWar("src/main/webapp");

        // START JMX SERVER
        // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
        // server.getContainer().addEventListener(mBeanContainer);
        // mBeanContainer.start();

        server.setHandler(bb);

        try {
            System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
            server.start();
            System.in.read();
            System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
            server.stop();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

I'm help that =)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top