jetty一个好的servlet容器项目工程中的配置及问题
1、jetty跟meven的结合pom.xml中的配置 org.mortbay.jettyjetty6.1.22providedorg.mortbay.jettyjsp-2.1-jetty6.1.22providedorg.mortbay.jettymaven-jetty-plugin6.1.22/fre
1、jetty跟meven的结合pom.xml中的配置
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1-jetty</artifactId>
<version>6.1.22</version>
<scope>provided</scope>
</dependency>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.22</version>
<configuration>
<contextPath>/fre</contextPath>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8787</port>
</connector>
</connectors>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
2、Jetty代码运行方式
public class ServerStart {static String path =
Thread.currentThread().getContextClassLoader().getResource("").getPath(); static String subPath = "src/main/webapp"; static String etcPath = "etc/webdefault.xml";
public static void main(String[] args) throws Exception {
System.out.println("正在启动....................");
long begin = System.currentTimeMillis();
Connector connector = new SelectChannelConnector(); connector.setPort(Integer.getInteger("jetty.port", 80).intValue());
WebAppContext webapp = new WebAppContext(getPath()+subPath, "/");
webapp.setDefaultsDescriptor(getPath()+etcPath);
Server server = new Server();
server.setConnectors(new Connector[] { connector }); server.setHandler(webapp); server.start();
System.out.println("Jetty Server started”);
}
private static String getPath(){ if(path.indexOf("/") == 0){ path = path.substring(1, path.length());
}
path = path.replace("target/test-classes/", ""); return path;
}
}
启动成功
3、注意:当启动jetty后修改不了静态html,js后无法保存,无论是在Eclipse里面保存还是在外部都无法保存。jetty 缓存了静态的html,js 和css等,不能被修改,但是JSP文件是可以修改的。
修改web.xml加入下面文件,再次重新启动,改html,js没问题
<servlet> <servlet-name>default</servlet-name>
<servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>useFileMappedBuffer</param-name> <param-value>false</param-value> </init-param>
<load-on-startup>0</load-on-startup>
</servlet>
最后注意:jetty中的项目放入tomcat中运行很多时候会出现错误
更多推荐
所有评论(0)