Java jetty.xml在maven项目中的位置?

Java jetty.xml在maven项目中的位置?,java,maven,jetty,Java,Maven,Jetty,我正在这里阅读jetty xml: . 它声明“jetty.xml是jetty的默认配置文件,通常位于$jetty_HOME/etc/jetty.xml”。但我的问题是,如果我获得jetty作为maven插件,我在哪里可以找到xml 以下是我的pom.xml: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:sc

我正在这里阅读jetty xml: . 它声明“jetty.xml是jetty的默认配置文件,通常位于$jetty_HOME/etc/jetty.xml”。但我的问题是,如果我获得jetty作为maven插件,我在哪里可以找到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>

因为您使用的是嵌入式Jetty(而不是在Jetty中运行),所以您应该将配置文件放在类路径上,即src/main/resources,这是一个标准的Maven位置

根据这一点,您应该加载资源文件并用它初始化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();
    }
}
这个例子是针对一个文件服务器的,但我想其他任何服务器都是类似的

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