日期:2014-05-16 浏览次数:20714 次
On this tutorial we will demonstrate how to setup Struts 2 in Eclipse, and make it work with Spring, Java Persistence API (using Hibernate) and Struts 2 Ajax tags.
NOTE: Following this tutorial verbatim will require use of a Struts 2 deployment greater than 2.0.3
Install Tomcat before going forward. See Tomcat's installation guide if you have any problem installing it.
Install and configure MySql. Create a database named "quickstart" and run the script below to create the "Person" table. Later, on applicationContext.xml, we'll use 'root' as the user name and password for the database, remember to replace those values with the right ones for your database.
CREATE TABLE 'quickstart'.'Person' ( 'id' INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, 'firstName' VARCHAR(45) NOT NULL, 'lastName' VARCHAR(45) NOT NULL, PRIMARY KEY('id') ) ENGINE = InnoDB;
You can just download the zipped Eclipse project, add the required dependencies to the lib folder under the /WebContent/WEB-INF/lib folder (relative to project's root folder) and import it into Eclipse.
To run the project this way you will need maven installed.
$ mvn install:install-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar -Dfile=c:\path\to\jar\jta-1.0.1B.jar
$ mvn jetty:run
$ mvn eclipse:eclipse
or (to create web project for WTP):
mvn eclipse:eclipse -Dwtpversion=1.0