该工程最初版本来自于Mybatis所在的google code站点,属于轻量级J2EE技术框架应用范围,使用了Spring、Stripes和MyBatis开源框架。其中Stripes为MVC框架的一种,该框架的设计和使用理念是零配置。熟悉该工程后主要是做了两方面的改进,一个是开发调试方面,另一个是数据库连接方面。
本文主要介绍开发调试方面:采用Jetty Web Server进行开发调试,效率更高。
方式1:maven命令行方式
该方式比较简单,只需在工程的pom文件里添加一个插件,其具体内容如下:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargetPatterns>
<scanTargetPattern>
<directory>src/main/webapp/WEB-INF</directory>
<excludes>
<exclude>***.properties</include>
<include>**
public static void main(String[] args) {
new PetStoreJettyServer();
}
// Jetty 6
public PetStoreJettyServer() {
//LOG.info("Starting web...");
try {
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[]{connector});
String[] tryPaths = new String[] {
"mybatis-jpetstore/src/main/webapp",
"../mybatis-jpetstore/src/main/webapp"
};
String webapp = System.getProperty("webapp");
if (webapp == null) {
for (String tryPath : tryPaths) {
if (new File(tryPath).exists()) {
webapp = tryPath;
}
}
}
if (webapp == null) {
//LOG.severe("Could not find suitable web app sources to deploy, failing");
return;
}
WebAppContext webappcontext = new WebAppContext();
webappcontext.setContextPath("/");
webappcontext.setWar(webapp);
HandlerCollection handlers= new HandlerCollection();
handlers.setHandlers(new Handler[]{webappcontext, new DefaultHandler()});
server.setHandler(handlers);
server.start();
try {
server.join();
} catch (InterruptedException e) {
//LOG.severe(e);
}
} catch (Exception e) {
//LOG.severe(e);
}
}
}
转载于:https://blog.51cto.com/minglu/920675