Follow these steps to build an MVC project using maven:
I. Objectives
In this article, I will show you how to use spring Frameworks and Maven build to create your first J2ee application.
II. Information
Maven is a Java Project Build tool (or automatic build tool ). It works with Ant or Gradle very much. Maven can automatically download the components that your project depends on.
Iii. Requirements
1. Spring Tool Suite (STS) (http://spring.io/tools/sts/all) applied to Java EE ).
Select the installation file corresponding to your operating system. I prefer to download a portable package version.
2. Network Connection
For the first creation of the Spring Mvc project, you need to connect to the computer because you need to download some project templates from Spring repository. Maven also needs to download some Spring dependencies. So check whether your computer is connected to the Internet. If you are in an Internet proxy environment, refer to this tutorial.
Iv. Configuration
1. Open your STS and select New-> Spring Project.
2. Name your Project (for example, HelloSpringMVC) and select the Spring MVC Project template.
3. STS will download the corresponding template.
4. Name your top-level package (for example, org. munif. app) and click Finish.
5. Observe the structure of your project and make an inexplicable error in your project. That's right. Because we have not used Maven to add Spring dependencies.
6. Right-click your Spring Mvc project and choose Run Sa> Maven install. Observe the output Console window to check whether the installation progress exists. After the installation is complete, you can proceed to the next step.
7. Right-click your Spring MVC Project and choose Maven> Update Project.
8. Select your project and click OK until the update process is complete.
No error.
9. Run your project, right-click the project folder, and choose Run As> Run on Server.
10. Select Your J2EE service "VMware vFabrics tc Server is provided by STS.". If you want to use an independent Apache Tomat, configure it accordingly.
11. Complete. Your project should be displayed in the Eclipse embedded web browser.
5. FAQs
1. Question #1
Build workspace error... Couldn't find build plan...
Cause: Your Maven dependency is not downloaded or unavailable.
Solution:
A. Make sure your computer is connected to the Internet.
B. Right-click your Spring MVC project and choose Run As> Maven install. Observe the output text window and check the installation progress. After the installation is complete, you can proceed to the next step.
C. Right-click your Spring MVC Project and choose Maven> Update Project.
2. Question #2
You are behind a proxy
Cause: your network environment is proxy surfing.
Solution:
A. Add the proxy configuration in your setting. xml file. After entering Preference, set this file to the Maven settings file. (somehow, settings. xml is not created by default, so you need to create this file by yourself .)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<Settingsxmlns = "http://maven.apache.org/SETTINGS/1.0.0" Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" Xsi: schemaLocation = "http://maven.apache.org/SETTINGS/1.0.0 Http://maven.apache.org/xsd/settings-1.0.0.xsd> <Proxies> <Proxy> <Id> myproxy </id> <Active> true </active> <Protocol> http </protocol> <Host> proxy.somewhere.com <Port> 8080 </port> <Username> proxyuser </username> <Password> somepassword </password> <NonProxyHosts> * .google.com | ibiblio.org </nonProxyHosts> </Proxy> </Proxies> </Settings> |
B. Right-click your Spring MVC project and choose Run As> Maven install. Observe the output Console window to ensure the installation progress is complete.
C. Right-click your Spring MVC Project and choose Maven> Update Project.
3. Question #3
Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
Generally, this error occurs in the Jsp file. See: http://stackoverflow.com/questions/15434817/can-not-find-the-tag-library-descriptor-for-http-java-sun-com-jsp-jstl-core.
Then, you can use Maven install and update Project to update the Project.
4. Question #4
When you run Maven install, the following error occurs:
[ERROR]... very long error...: invalid LOC header (bad signature ).
Cause: This indicates that some dependent binary files may be damaged.
Solution:
Delete ". m2/repository" and run Maven install to re-download the dependency repository.
5. Question #5
[ERROR]... very long errors...: UnresolvedAddressException
Cause:
A. if you use a domain name proxy (for example, proxy. its. ac. id) in the settings. xml file, it means that your DNS cannot resolve the domain name address.
B. If you connect directly to the network, but you still use the proxy configuration in settings. xml.
Solution:
A. In the first case, use the IP address proxy in the settings. xml file to replace the domain name.
B. If the network is connected directly, delete the proxy configuration in the settings. xml file.
Finally, we hope this tutorial will help you use STS for Spring mvc development.
Vi. References
[1] http://www.mkyong.com/web-development/how-to-configure-proxy-settings-in-eclipse/
[2] http://maven.apache.org/settings.html
[3] http://stackoverflow.com/questions/13044628/spring-error-during-build
Http://abdulmuneverlose.wordpress.com/2013/12/19/first-spring-mvc-project-using-spring-tool-suite-sts-and-maven-build/.