Spring MVC Fast Tutorial: Setup
This tutorial is out of date. See the new version for Spring 4.
You'll need java 1.5, ant and tomcat. We're going to:
-
create a web app skeleton
-
add build files
-
add required JARs
Web App Skeleton
Create a new folder 'springmvc'.
Inside, create these folders: 'classes', 'jsp', 'WEB-INF'.
In 'jsp', add 'index.jsp':
<html>
<body>
<p>Hi</p>
</body>
</html>
In 'WEB-INF', add 'web.xml' and create the folder 'src':
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <welcome-file-list> <welcome-file> jsp/index.jsp </welcome-file> </welcome-file-list> </web-app>
Add 'springmvc' folder to Tomcat webapps's folder, launch Tomcat and test (your Tomcat port may differ): http://localhost:8180/springmvc/
Build files
In 'WEB-INF', add 'build.properties': (update Tomcat path)
appserver.home=/usr/share/tomcat5.5 appserver.lib=${appserver.home}/common/lib
In 'WEB-INF', add 'build.xml':
<?xml version="1.0" encoding="UTF-8"?> <project basedir="." default="build"> <property file="build.properties"/> <property name="src.dir" value="src"/> <property name="build.dir" value="classes"/> <path id="build.classpath"> <fileset dir="lib"> <include name="*.jar"/> </fileset> <fileset dir="${appserver.lib}"> <!-- servlet API classes: --> <include name="servlet*.jar"/> </fileset> <pathelement path="${build.dir}"/> </path> <target name="build"> <mkdir dir="${build.dir}"/> <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true"> <src path="${src.dir}"/> <classpath refid="build.classpath"/> </javac> </target> <target name="clean" description="Clean output directories"> <delete> <fileset dir="${build.dir}"> <include name="**/*.class"/> </fileset> </delete> </target> </project>
JARs
In 'WEB-INF', create the folder 'lib'.
Add into it these JARs from Spring distribution (with dependencies):
-
spring-framework/dist/spring.jar
-
spring-framework/dist/modules/spring-webmvc.jar
-
spring-framework/lib/jakarta-taglibs/standard.jar
-
spring-framework/lib/jakarta-commons/commons-logging.jar
-
spring-framework/lib/j2ee/servlet-api.jar
-
spring-framework/lib/j2ee/jstl.jar
Summary
You can download it here.
from: http://jeromejaglale.com/doc/java/spring/setup