简体   繁体   English

jetty.xml在Maven项目中的位置?

[英]Location of jetty.xml in a maven project?

Im reading about jetty xml from here: http://www.eclipse.org/jetty/documentation/current/jetty-xml-config.html . 我从这里阅读有关jetty xml的信息: http : //www.eclipse.org/jetty/documentation/current/jetty-xml-config.html It states that "jetty.xml is the default configuration file for Jetty, typically located at $JETTY_HOME/etc/jetty.xml". 它指出“ jetty.xml是Jetty的默认配置文件,通常位于$ JETTY_HOME / etc / jetty.xml中”。 But my question is that if i obtain jetty as a maven plugin there where can i find the xml? 但是我的问题是,如果我将码头作为Maven插件获得,在哪里可以找到xml?

Here is my pom.xml: 这是我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>jet</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>jet</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>8.1.3.v20120416</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlet</artifactId>
            <version>8.1.3.v20120416</version>
        </dependency>
    </dependencies>
</project>

and here is how i start server: 这是我如何启动服务器:

package com.example.jet; 包com.example.jet;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

public class App {
    public static void main(String[] args) throws Exception {
        Server s = new Server(8080);
        s.setSendDateHeader(true);
        ServletContextHandler c = new ServletContextHandler(s, "/");
        c.addServlet(new ServletHolder(new MyServlet()), "/hello");
        s.setHandler(c);
        s.start();
    }
}

Since you are using embedded Jetty (not running it in Jetty) so you should put your configuration file on the classpath ie src/main/resources, which is a standard Maven location. 由于您使用的是嵌入式Jetty(不在Jetty中运行),因此应将配置文件放在类路径(即src / main / resources)上,这是标准的Maven位置。

According to this tutorial you should then load the resource file and initialize Jetty with it: 根据本教程,您应该然后加载资源文件并使用它初始化Jetty:

public class FileServerXml
{
    public static void main(String[] args) throws Exception
    {
        Resource fileserver_xml = Resource.newSystemResource("fileserver.xml");
        XmlConfiguration configuration = new XmlConfiguration(fileserver_xml.getInputStream());
        Server server = (Server)configuration.configure();
        server.start();
        server.join();
    }
}

The example is for a file server but I imagine it is similar for any other. 该示例适用于文件服务器,但我想它与其他任何服务器都相似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM