Eclipse使用maven构建web项目(安装、配置、运行jetty服务器)

二、安装、配置、运行jetty服务器

1、安装jetty

未来需要将项目打包为war包发布到服务器容器中使用jetty

在中央仓库查找org.mortbay.jetty的配置坐标,并在pom.xml中自定义插件。

https://mvnrepository.com/artifact/org.mortbay.jetty/jetty-maven-plugin/8.1.16.v20140903

2、用jetty插件运行容器

右键项目->run as->Maven build输入jetty:run

显示Started Jetty Server 表示启动成功

浏览器输入http://localhost:8080/ 访问

3、绑定jetty插件,设置为打包阶段运行jetty服务

   pom.xml在<executions>中添加添加绑定打包后自动运行服务了

<build>
        <finalName>webDemo</finalName>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.16.v20140903</version>
                <executions>
                    <execution>
                        <!-- 在打包成功后使用jetty:run来运行jetty服务 -->
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

猜你喜欢

转载自www.cnblogs.com/404code/p/10564066.html