Environment building for getting started with Spring MVC instances

Source: Internet
Author: User
Tags echo message

Reprint Please specify source: http://blog.csdn.net/pearyangyang/article/details/42467729

Spring MVC is one of the Spring family framework, which is separated by the controller and model objects and integrates with spring technology to make the architecture of the system clear.

Previously prepared:

1.JDK Installation and configuration

Path:; C:\Program Files\java\jdk1.6.0_17\bin

Add a system variable to the environment variable java_home and configure: C:\Program files\java\jdk1.6.0_17

Added system variable classpath:.; %java_home%\lib;%java_home%\lib\tools.jar (note. Dot and; delimiter)

Verify (in cmd): java-version

2.Tomcat Installation and configuration

Add a catalina_home: E:\tools\apache-tomcat-7.0.57

added in path:;%catalina_home%\bin

Verify (in cmd): Startup.bat, the smooth start can be.

installation and configuration of 3.ant

Add a catalina-ant-classpath: E:\tools\apache-ant-1.9.4

added in path:;%catalina-ant-classpath%\bin

Verify (in cmd): ant-version

For all packages please see the link below:

http://download.csdn.net/detail/yangliding2011/8335613

Create a new Dynamic Web application named Springapp, in order to combine with ant, we changed webcontent to war file, the program structure is as follows:

Create a index.jsp file, located in Springmvc1.0/war/index.jsp, with the following contents:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

We then configure Web. XML, located in Springmvc1.0/war/web-inf/web.xml, with the following content:

<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "3.2" xmlns= "http://java.sun.com/xml/ns/         Java ee "         xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "         xsi:schemalocation=" http://java.sun.com/ Xml/ns/javaee;         Http://java.sun.com/xml/ns/javaee/web-app_3_2.xsd "><welcome-file-list>    <welcome-file>      index.jsp    </welcome-file>  </welcome-file-list></web-app>

At this point we can deploy the project directly to Tomcat through Ant, I use tomcat7.0.57, the following is Build.xml, location in Springmvc1.0/build.xml, the content is as follows:

<?xml version= "1.0" encoding= "UTF-8"? ><project name= "springmvc1.0" basedir= "." default= "Usage" > < Property file= "Build.properties"/> <property name= "src.dir" value= "src"/> <property name= "Web.dir" value = "war"/> <property name= "Build.dir" value= "${web.dir}/web-inf/classes"/> <property name= "name" value= "sp ringmvc1.0 "/> <path id=" Master-classpath "> <fileset dir=" ${web.dir}/web-inf/lib "> <  Include name= "*.jar"/> </fileset> <!--We need the servlet API classes:--<!--* For Tomcat 5/6 use Servlet-api.jar-<!--* For other apps Servers-check the docs-to-<file Set dir= "${appserver.lib}" > <include name= "Servlet*.jar"/> </fileset> <pathelem ent path= "${build.dir}"/> </path> <target name= "Usage" > <echo message= ""/> <ec Ho message= "${name} Build File"/> <echo message= "-----------------------------------"/> <echo message= ""/> <echo m Essage= "Available targets is:"/> <echo message= ""/> <echo message= "Build---build the A Pplication "/> <echo message=" deploy--and deploy application as directory "/> <echo message=" Deploywar---Deploy application as a WAR file "/> <echo message=" Install--install application in T     Omcat "/> <echo message=" Reload--Reload application in Tomcat "/> <echo message=" start -Start Tomcat Application "/> <echo message=" stop--stop tomcat application "/> &lt echo message= "List--list Tomcat applications"/> <echo message= "/> </target> <t Arget name= "Build" description= "Compile main source tree java files" > <mkdir dir= "${build.dir}"/> & Lt;javac destdir= "${builD.dir} "source=" 1.6 "target=" 1.6 "debug=" true "deprecation=" false "Optimize=" false "failonerror=" true "> <src path= "${src.dir}"/> <classpath refid= "Master-classpath"/> </javac> & Lt;/target> <target name= "deploy" depends= "Build" description= "Deploy Application" > <copy todir= "${d Eploy.path}/${name} "preservelastmodified=" true "> <fileset dir=" ${web.dir} "> <includ E name= "**/*.*"/> </fileset> </copy> </target> <target name= "Deploywar" de pends= "Build" description= "Deploy application as a WAR file" > <war destfile= "${name}.war" webxml=             "${web.dir}/web-inf/web.xml" > <fileset dir= "${web.dir}" > <include name= "**/*.*"/>            </fileset> </war> <copy todir= "${deploy.path}" preservelastmodified= "true" > <fileset dir="." > <include name= "*.war"/> </fileset> </copy> </target> & lt;! --If your service is not tomcat, you can configure other services--<path id= "Catalina-ant-classpath" > <!--We need the Catalina jars fo R Tomcat-<!--* For other apps Servers-check the docs-to <fileset dir= "${appserver.lib}" &            Gt <include name= "Catalina-ant.jar"/> <include name= "Tomcat-coyote.jar"/> <include name  = "Tomcat-util.jar"/> </fileset> <fileset dir= "${appserver.home}/bin" > <include Name= "Tomcat-juli.jar"/> </fileset> </path> <taskdef name= "Install" classname= "Org.apache". Catalina.ant.DeployTask "> <classpath refid=" Catalina-ant-classpath "/> </taskdef> <taskdef N   Ame= "Reload" classname= "Org.apache.catalina.ant.ReloadTask" > <classpath refid= "Catalina-ant-classpath"/> </taskdef> <taskdef name= "list" classname= "Org.apache.catalina.ant.ListTask" > <classpath refid= " Catalina-ant-classpath "/> </taskdef> <taskdef name=" Start "classname=" Org.apache.catalina.ant.StartTask "> <classpath refid=" Catalina-ant-classpath "/> </taskdef> &lt ; Taskdef name= "Stop" classname= "Org.apache.catalina.ant.StopTask" > <classpath refid= "Catalina-ant-classpath" /> </taskdef> <target name= "Install" description= "Install application in Tomcat" > <install Url= "${tomcat.manager.url}" Username= "${tomcat.manager.username}" password= "${tomcat.manag Er.password} "path="/${name} "war=" ${name} "/> </target> <target name=" re Load "description=" Reload application in Tomcat "> <reload url=" ${tomcat.manager.url} "Usernam E= "${tomcat.manager.username}" password= "${Tomcat.manager.password} "path="/${name} "/> </target> <target name=" Start "description=" Start Tomcat Application "> <start url=" ${tomcat.manager.url} "Username=" ${tomcat.manager.user Name} "password=" ${tomcat.manager.password} "path="/${name} "/> </target> &l                 T;target name= "Stop" description= "Stop Tomcat Application" > <stop url= "${tomcat.manager.url}" Username= "${tomcat.manager.username}" password= "${tomcat.manager.password}" path= "/${name } "/> </target> <target name=" list "description=" list Tomcat applications "> <list url=" ${tom Cat.manager.url}/text "Username=" ${tomcat.manager.username} "password=" ${TOMCAT.MANAGER.PA ssWOrd} "/> </target> <!--END Tomcat configuration--></project>

Through the configuration file, read the common parameters, build.properties, the location is as follows: Springmvc1.0/build.properties

# Ant Properties for building the springappappserver.home=e:/tools/apache-tomcat-7.0.57#-Tomcat 5 use $appserver. Home }/server/lib# for Tomcat 6 use $appserver. Home}/libappserver.lib=${appserver.home}/libdeploy.path=${appserver.home} /webappstomcat.manager.url=http://localhost:8080/managertomcat.manager.username=tomcattomcat.manager.password=s3cret

To configure Tomcat-user.xml, in the Tomcat-user.xml file under Tomcat under the Conf folder, add the configured administrator entity:

<?xml version= ' 1.0 ' encoding= ' utf-8 '?><tomcat-users> <role rolename=  ' manager '/>  < User Username= "Tomcat" password= "S3cret" roles= "manager"/></tomcat-users>
Open the DOS command, specify the path to the project path, and use the ant directive to see if the project is wrong.


Ant Deploy command to deploy the project to Tomcat, using either the ant deploy or ant Deploywar commands:


Finally, you can view the deployed project in the corresponding Tomcat directory WebApps, open the Web page, enter http://localhost:8080/springmvc1.0/index.jsp, as shown below:


We can also log in to the Tomcat admin interface http://localhost:8080/manager with Tomcat user rights to view server-related information:

Well, the pre-preparatory work we have OK, and finally we look at the directory structure of the document, and our usual difference is that the WebContent file package name into the war package:


Note tips:

1. In the case of TOMCAT5 or 6, the install should refer to the Installtask class when Build.xml is configured, and 7 or higher is Org.apache.catalina.ant.DeployTask

2. Fix warning: ' Includeantruntime ' is not set problem, add Includeantruntime= "on" to build


Code Download: http://download.csdn.net/detail/yangliding2011/8355879

Translated from: http://docs.spring.io/docs/Spring-MVC-step-by-step/part1.html


Environment building for getting started with Spring MVC instances

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.