struts2.3.20环境搭建详解
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Create Struts 2 Web Application With Artifacts In WEB-INF lib and Use Ant To Build The Application
Edit Page Browse Space Add Page Add News
You can download this complete example, Basic_Struts2_Ant, from Google Code
- /p/struts2-examples/downloads/list. Click on the link for
Basic_Struts2_Ant.zip and save the file to your computer. Unzip the file and you should have a folder named Basic_Struts2_Ant. In that folder is a README.txt file with instruction on how to build and run the application.
Icon
This tutorial assumes you already know how to create a Java web application, use Ant to build the web application archive (war) file, and deploy the war file to a Servlet container such as Tomcat or Jetty.
To create a Struts 2 web application with the Struts 2 artifacts added to the the application's class path manually you will need to download the Struts 2 distribution from the Apache Struts website.
On the Struts 2 download page, click on the link for the current General Availability release. In that release's section you'll find several links. To get started with a basic Struts 2 web application you need to only download the Essential Dependencies Only zip file, which is approximately 12mb.
After downloading this zip file, unzip it. You should have a folder named the same as the current general availability release and in that folder will be a lib folder. The lib folder contains the Struts 2 jar files (e.g. struts2-core-X.X.X.X.jar, where X.X.X.X is the version) and other jar files Struts 2 requires (e.g. xwork-core.X.X.X.jar).
As we create our basic Struts 2 web application we will copy from the Struts 2 distribution lib folder just the jar files our application requires. As we add features to our application in future tutorials we will copy other jar files.
Step 1 - Create A Basic Java Web Application
In your Java IDE create a web application project named Basic_Struts2_Ant. To follow along with this tutorial your web application should have the following folder structure:
Remember Struts 2 requires Servlet API 2.4 or higher, JSP 2.0 or higher, and Java 5 or higher. The example project, Basic_Struts2_Ant, which you can download from Google
code /p/struts2-examples/downloads/list was created using Eclipse 3.5 with Java 6.
Step 2 - Add index.jsp and Ant Build File
Our next step is to add a simple index.jsp to this web application. Create an index.jsp under WebContent with a title of "Basic Struts 2 Application - Welcome" and in the body add an h1 heading of "Welcome to Struts 2!"
Next create an Ant build.xml file that will compile any Java classes and create the war file. The code example download, Basic_Struts2_Ant, includes an Ant build.xml.
Run the Ant target that creates the war file (in the example downloaded that is the archive target, which places the war file in the dist folder). Copy the war file into your Servlet container so that it will deploy the war file.
Start up your Servlet container and in a web browser go
to http://localhost:8080/Basic_Struts2_Ant/index.jsp. You should see the following:
Step 3 - Add Struts 2 Jar Files To Class Path
Now that we know we have a working Java web application, lets add the minimal required Struts 2 framework Jar files to our web application's class path. We'll copy these Jar files from the lib folder of the Struts 2 download to the WEB-INF/lib folder in our web application.
Find and copy to WEB-INF\lib these files (note X.X.X.X.jar refers to the version number):
1.asm-x.x.jar
2.asm-commons-x.x.jar
3.asm-tree-x.x.jar
mons-io-X.X.X.jar
mons-lang3-X.X.X.jar
mons-fileupload-X.X.X.jar
7.freemarker-X.X.X.jar
8.javassist-X.X.X.jar
9.ognl-X.X.X.jar
10.struts2-core-X.X.X.X.jar
11.xwork-core-X.X.X.jar
You can see from the above that the Struts 2 core jar depends on several other artifacts. As we add additional Struts 2 features in future tutorials, we'll need to add additional Struts 2 jar files and other transitive dependencies.