Приложение Wicket со встроенным сервером на причале

Как я могу включить встроенный сервер причала в моем приложении калитки, который мог бы позволить мне управлять моим приложением таким демоном, как указано выше:

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

Так работает приложение Rundeck, использующее фреймворк Grails. Уточнение Google использует тот же подход. Для меня приятно использовать веб-приложение таким же образом.

Кто-нибудь знает хорошие ресурсы или статьи, объясняющие эту тему, с maven?

Кроме того, можно настроить причал, чтобы предлагать функцию обновления в реальном времени, такую ​​как предложения игрового фреймворка или как использование JRebel?


person Bera    schedule 28.01.2013    source источник
comment
похоже на аналогичный вопрос к stackoverflow.com/questions/12737542/   -  person Anton Arhipov    schedule 01.02.2013


Ответы (1)


Если вы используете 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);
        }
    }

Я помогу в этом =)

person Leodev    schedule 03.06.2013