以下适合于使用maven管理的web工程,运行在jetty容器下:
1.添加jetty的maven插件端口号8080和scan间隔
<build>
<finalName>lmp-service</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
</connector>
</connectors>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</build>
2.在Intell Idea中配置:
Run/Debug Configuration中add 一个maven configuration:
指定项目工程路径,goals设置为jetty:run,同时不要忘记在General和Runner中设置maven路径和jdk
3.启动debug即可
4.如果应用中需要添加数据源,可以直接在maven plugin中指定:
<jettyEnvXml>src/main/resources/jetty-env-test.xml</jettyEnvXml>
对应的数据源内容可以是:
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
- "http://jetty.mortbay.org/configure.dtd">
- <Configure class="org.mortbay.jetty.webapp.WebAppContext">
- <New id="dataSource" class="org.mortbay.jetty.plus.naming.Resource">
- <Arg>jdbc/osworkflow</Arg>
- <Arg>
- <New class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
- <Set name="url">jdbc:mysql://localhost:3306/osworkflow?useUnicode=true&characterEncoding=UTF-8</Set>
- <Set name="user">root</Set>
- <Set name="password"></Set>
- </New>
- </Arg>
- </New>
- </Configure>
当然,如果你的plugin中缺少需要依赖的jar包,也可以在pom文件中配置添加,比如需要dbcp的数据源依赖,那可能你工程中缺少对应jar包,可以如下:
在jetty plungin中假如依赖:
- <plugin>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>maven-jetty-plugin</artifactId>
- <version>6.1.26</version>
- <dependencies>
- <dependency>
- <groupId>commons-dbcp</groupId>
- <artifactId>commons-dbcp</artifactId>
- <version>1.3</version>
- </dependency>
- </dependencies>
- <configuration>
- <connectors>
- <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
- <port>8080</port>
- </connector>
- </connectors>
- <jettyEnvXml>src/main/resources/jetty-env-idea.xml</jettyEnvXml>
- <scanIntervalSeconds>10</scanIntervalSeconds>
- </configuration>
- </plugin>