2

如何在我的 wicket 应用程序中启用一个 jetty 嵌入式服务器,它可以让我以像上面这样的守护程序方式控制我的应用程序:

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

使用 Grails 框架的 Rundeck 应用程序以这种方式工作。谷歌优化使用相同的方法。对我来说,以同样的方式使用 Web 应用程序真是太棒了。

有人知道用 maven 解释这个主题的好资源或文章吗?

此外,可以配置码头以提供实时更新功能,如播放框架提供或使用 JRebel?

4

1 回答 1

2

如果使用 maven,您可以提供以下帮助:

聚甲醛:

  <!--  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>

主类:

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);
        }
    }

我帮忙=)

于 2013-06-03T15:52:59.593 回答