Hatred's Log Place

DON'T PANIC!

Nov 17, 2011 - 4 minute read - programming

Jetty, JSP и Maven

На правах заметки:

  • Список зависимостей для Maven, что бы получить последнюю (8.0.4) версию embedded Jetty и получить рабочий JSP.
  • Конфиг для embedded Jetty, что бы завёлся JSP.

Подробности подкатом

Список зависимостей для Maven

По сути полная версия Jetty, убирать зависимости, если какие не нужны.

Сначала в начале POM файла прописать:

    <properties>
        <jetty-version>8.0.4.v20111024</jetty-version>
        <jetty-hightide-version>8.0.4.v20111024</jetty-hightide-version>
    </properties>

Далее в список зависимостей добавить:

        <!-- Jetty Dependency           -->
        <!-- exclude unneeded artifacts -->
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-deploy</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-rewrite</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-ajp</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-annotations</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>test-jetty-webapp</artifactId>
            <type>war</type>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-jmx</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-jndi</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-plus</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-client</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-continuation</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-start</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-policy</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-websocket</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <!-- JSP & JSTL & EL -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>jsp-impl</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <type>jar</type>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>jstl-impl</artifactId>
            <type>jar</type>
            <exclusions>
                <exclusion>
                    <artifactId>servlet-api</artifactId>
                    <groupId>javax.servlet</groupId>
                </exclusion>
            </exclusions>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <type>jar</type>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <type>jar</type>
            <version>2.2</version>
        </dependency>
        <!-- From Jetty Hightide -->
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-setuid-java</artifactId>
            <version>${jetty-hightide-version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-spring</artifactId>
            <version>${jetty-hightide-version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>libsetuid</artifactId>
            <version>${jetty-hightide-version}</version>
            <type>so</type>
        </dependency>

Конфиг Jetty

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-*Jetty*Configure*EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="WebManagementConsole" class="org.eclipse.jetty.server.Server">

    <!-- =========================================================== -->
    <!-- Define some SystemProperties                                -->
    <!-- =========================================================== -->
    <Call class="java.lang.System" name="setProperty">
        <Arg>jetty.home</Arg>
        <Arg><SystemProperty name="jetty.home" default="."/></Arg>
    </Call>
    <Call class="java.lang.System" name="setProperty">
        <Arg>derby.system.home</Arg>
        <Arg><SystemProperty name="java.io.tmpdir"/></Arg>
    </Call>
    <!--
    <Call class="java.lang.System" name="setProperty">
        <Arg>org.eclipse.jetty.util.log.stderr.DEBUG</Arg>
        <Arg>false</Arg>
    </Call>
    <Call class="java.lang.System" name="setProperty">
        <Arg>org.eclipse.jetty.util.log.stderr.SOURCE</Arg>
        <Arg>false</Arg>
    </Call>
    -->
    <!-- disable internal JSP compiller -->
    <Call class="java.lang.System"  name="setProperty">
        <Arg>org.apache.jasper.compiler.disablejsr199</Arg>
        <Arg>true</Arg>
    </Call>


    <!-- =========================================================== -->
    <!-- JMX                                                         -->
    <!-- =========================================================== -->


    <!-- =========================================================== -->
    <!-- Initialize an mbean server                                  -->
    <!-- =========================================================== -->
    <Call id="MBeanServer" class="java.lang.management.ManagementFactory" name="getPlatformMBeanServer" />

    <!-- =========================================================== -->
    <!-- Initialize the Jetty MBean container                        -->
    <!-- =========================================================== -->
    <New id="MBeanContainer" class="org.eclipse.jetty.jmx.MBeanContainer">
        <Arg>
            <Ref id="MBeanServer" />
        </Arg>
    </New>

    <!-- Add to the Server to listen for object events -->
    <Get id="Container" name="container">
        <Call name="addEventListener">
            <Arg>
                <Ref id="MBeanContainer" />
            </Arg>
        </Call>
    </Get>

    <!-- Add to the Server as a lifecycle -->
    <!-- Only do this if you know you will only have a single jetty server -->
    <Call name="addBean">
        <Arg>
            <Ref id="MBeanContainer" />
        </Arg>
    </Call>

    <!-- Add the static log -->
    <Get id="Logger" class="org.eclipse.jetty.util.log.Log" name="log" />
    <Ref id="MBeanContainer">
        <Call name="addBean">
            <Arg>
                <Ref id="Logger" />
            </Arg>
        </Call>
    </Ref>


    <!-- =========================================================== -->
    <!-- Set conntectors                                             -->
    <!-- =========================================================== -->
    <Call name="addConnector">
        <Arg>
            <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <Set name="host"><Property name="jetty.host" /></Set>
                <Set name="port"><Property name="jetty.port" default="8080"/></Set>
            </New>
        </Arg>
    </Call>

    <Set name="handler">
        <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
            <Set name="handlers">
                <Array type="org.eclipse.jetty.server.Handler">
                    <Item>
                        <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
                    </Item>
                    <Item>
                        <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
                    </Item>
                </Array>
            </Set>
        </New>
    </Set>


    <!-- Deploy Manager -->
    <Call name="addBean">
        <Arg>
            <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
                <Set name="contexts">
                    <Ref id="Contexts" />
                </Set>
                <Call name="setContextAttribute">
                    <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
                    <Arg>.*/servlet-api-[^/]*<br/>.jar$</Arg>
                </Call>
            </New>
        </Arg>
    </Call>



    <!-- Add a WebAppProvider to the deployment manager                  -->
    <Ref id="DeploymentManager">
        <Call id="webappprovider" name="addAppProvider">
            <Arg>
                <New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
                    <Set name="monitoredDirName">
                        <SystemProperty name="jetty.home"/>/webapps
                    </Set>
                    <Set name="defaultsDescriptor">
                        <SystemProperty name="jetty.home"/>/etc/webdefault.xml
                    </Set>
                    <Set name="contextXmlDir">
                        <SystemProperty name="jetty.home"/>/contexts
                    </Set>
                    <Set name="scanInterval">1</Set>
                    <!-- UNCOMMENT if extracting needed -->
                    <Set name="extractWars">false</Set>
                </New>
            </Arg>
        </Call>
    </Ref>


    <!-- Add a ContextProvider to the deployment manager                 -->
    <Ref id="DeploymentManager">
        <Call name="addAppProvider">
            <Arg>
                <New class="org.eclipse.jetty.deploy.providers.ContextProvider">
                    <Set name="monitoredDir">
                        <SystemProperty name="jetty.home"/>/contexts
                    </Set>
                    <Set name="scanInterval">1</Set>
                </New>
            </Arg>
        </Call>
    </Ref>


    <Ref id="Handlers">
        <Call name="addHandler">
            <Arg>
                <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler">
                    <Set name="requestLog">
                        <New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog">
                            <Set name="filename"><Property name="jetty.logs" default="./log"/>/web-console-yyyy-mm-dd.request.log</Set>
                            <Set name="filenameDateFormat">yyyy_MM_dd</Set>
                            <Set name="retainDays">90</Set>
                            <Set name="append">true</Set>
                            <Set name="extended">false</Set>
                            <Set name="logCookies">false</Set>
                            <Set name="LogTimeZone">GMT</Set>
                        </New>
                    </Set>
                </New>
            </Arg>
        </Call>
    </Ref>


    <!--
    <New id="ServerLog" class="java.io.PrintStream">
      <Arg>
        <New class="org.eclipse.jetty.util.RolloverFileOutputStream">
          <Arg><Property name="jetty.logs" default="./log"/>/web-console-yyyy-mm-dd.stderrout.log</Arg>
          <Arg type="boolean">false</Arg>
          <Arg type="int">90</Arg>
          <Arg><Call class="java.util.TimeZone" name="getTimeZone"><Arg>GMT</Arg></Call></Arg>
          <Get id="ServerLogName" name="datedFilename"/>
        </New>
      </Arg>
    </New>

    <Call class="org.eclipse.jetty.util.log.Log" name="debug">
        <Arg>Redirecting stderr/stdout to <Ref id="ServerLogName"/></Arg>
    </Call>
    <Call class="java.lang.System" name="setErr"><Arg><Ref id="ServerLog"/></Arg></Call>
    <Call class="java.lang.System" name="setOut"><Arg><Ref id="ServerLog"/></Arg></Call>
    -->

    <!--
    <Get id="oldhandler" name="handler"/>
    <Set name="handler">
      <New id="DebugHandler" class="org.eclipse.jetty.server.handler.DebugHandler">
        <Set name="handler"><Ref id="oldhandler"/></Set>
        <Set name="outputStream">
          <New class="org.eclipse.jetty.util.RolloverFileOutputStream">
            <Arg type="String"><Property name="jetty.logs" default="./log"/>/web-console-yyyy-mm-dd.debug.log</Arg>
            <Arg type="boolean">true</Arg>
            <Arg type="int">90</Arg>
          </New>
        </Set>
      </New>
    </Set>
    -->
</Configure>

Ну а создавать сервер примерно так:

  XmlConfiguration configuration = new XmlConfiguration(new File("jetty-config.xml").toURI().toURL());
  Server server = new Server();
  configuration.configure(server);
  server.start();

Tags: java jetty jsp maven programming

Hibernate Tutorial Hibernate + SQLite

comments powered by Disqus