用Maven2构建Struts2的WEB应用

1.下载Maven,地址是:http://maven.apache.org/download.html

2.如果用的是Windows环境,要这样设置环境变量:添加Maven2的bin目录到path上去。

3.通常JAVA开发都使用Eclipse,给Eclipse添加Maven2的插件:添加更新网址http://m2eclipse.codehaus.org/update到Eclipse上的find and install那里去。

4.创建struts2项目,先去看看最新的SNAPSHOT,目的是看看里面使用的struts2是哪个版本,然后在cmd里面进入要创建程序的目录,运行以下命令:


mvn archetype:create -DgroupId=com.demo -DartifactId=struts2Demo -DarchetypeGroupId=org.apache.struts -DarchetypeArtifactId=struts2-archetype-starter -DarchetypeVersion=2.0.11.2-SNAPSHOT -DremoteRepositories=http://people.apache.org/repo/m2-snapshot-repository

5.过一段时间之后,项目构建成功,要支持Eclipse,则要进入struts2Demo目录,运行命令:

mvn eclipse:eclipse

6.打开Eclipse,导入项目就可以了。这里介绍一个轻量级容器叫jetty,进入项目的目录之后运行命令:mvn jetty:run,就可以下载并运行了。打开http://localhost:8080/struts2Demo/index.jsp,就可以访问应用程序了。

猜你喜欢

转载自sunrysoft.iteye.com/blog/908433