First Spring MVC project using Spring Tool Suite (STS) and Maven build

Goal(s)

In this article I will show you how to create your first J2EE applications using Spring Framework and Maven build.

Info

Maven is a build tools (or automation tools) for Java project. It is similar with Ant or Gradle. Maven can automatically download the required dependencies for your project.

Requirements

  1. Spring Tool Suite (STS) for Java EE (http://spring.io/tools/sts/all).
    Please choose the file according to your OS. I prefer to download the archive version because of its portability.
  2. An internet connection.
    For the first time creating a Spring MVC project, internet connection is REQUIRED. You need to download some project templates from Spring repository. Maven also would like to download some dependencies for Spring. Make sure that you have internet connection. If you are behind a proxy, please refer to this tutorial [1].

Instructions

  1. Open your Spring Tool Suite, and choose New -> Spring Project.
    Snap 2013-12-19 at 12.44.42
  2. Name your project (for example: HelloSpringMVC) and choose Spring MVC Project template.
    Snap 2013-12-19 at 12.47.37
  3. STS will downloads the required template.
    Snap 2013-12-19 at 12.48.43
  4. Name your top level package (for example: org.munif.app) and click Finish.
    Snap 2013-12-19 at 12.49.37
  5. Observe your project structure. Somehow there is an error in your project and IT IS ALL RIGHT. It is because we haven’t add the Spring dependencies using Maven, so the project will error.
    Snap 2013-12-19 at 12.53.49
  6. Right click your Spring MVC project, choose Run As -> Maven install. Observe the output console to see the installation progress. After the installation is finished, you can continue to the next step.
    Snap 2013-12-19 at 12.54.13Snap 2013-12-19 at 12.54.59
  7. Right click your Spring MVC project, choose Maven -> Update Project.
    Snap 2013-12-19 at 12.55.22
  8. Choose your project and click OK. Wait until update process is finished.
    Snap 2013-12-19 at 12.56.06
    No more errors.
    Snap 2013-12-19 at 14.30.00
  9. Run your project. Right click the project folder and choose Run As -> Run on Server.
    Snap 2013-12-19 at 13.08.49
  10. Choose your J2EE server.
    VMware vFabrics tc Server is provided by STS.
    If you want to use your standalone Apache Tomcat please make required configuration.
    Snap 2013-12-19 at 13.09.15Snap 2013-12-19 at 13.09.32
  11. Finished. Your project should be shown on Eclipse internal browser.
    Snap 2013-12-19 at 13.09.57

Common problems

Problem #1

Build workspace error … couldn’t find build plan …

Cause: Your Maven dependencies are incomplete or not available.
Solution:

  1. Make sure you are connected to the internet.
  2. Right click your Spring MVC project, choose Run As -> Maven install. Observe the output console to see the installation progress. After the installation is finished, you can continue to the next step.
  3. Right click your Spring MVC project, choose Maven -> Update Project.

Problem #2

You are behind a proxy

  1. Add proxy configuration on your settings.xml file [2]. Check in the Preferences where your Maven settings file located. (Somehow, settings.xml is NOT CREATED by default. So you need to create this file.)
    <settings xmlns="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</host>
    <port>8080</port>
    <username>proxyuser</username>
    <password>somepassword</password>
    <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
    </proxy>
    </proxies>
    </settings>
    

    Snap 2013-12-19 at 14.09.36

  2. Right click your Spring MVC project, choose Run As -> Maven install. Observe the output console to see the installation progress.
  3. Right click your Spring MVC project, choose Maven -> Update Project.

Problem #3

Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

Usually it happens on JSP files. Please refer to http://stackoverflow.com/questions/15434817/can-not-find-the-tag-library-descriptor-for-http-java-sun-com-jsp-jstl-core.
After that, you can use Maven install and update project.

Problem #4

When you are running Maven install, sometimes there is an error like this.

[ERROR] ... very long error ...: invalid LOC header (bad signature).

Cause: It  suggests that some binary file being broken, most likely one of the dependencies [3].

Solution:

The solutions is to delete the “.m2/repository”. And then run Maven install to let Maven download the repository again for you.

Problem #5

[ERROR] ... very long errors...: UnresolvedAddressException

Cause:

  • If you are using proxy with domain name (for example: proxy.its.ac.id) on your settings.xml file, it means that your DNS can not resolve this address.
  • You are using direct connection, but you still write proxy configurations on settings.xml.

Solution:

  1. Instead of domain name, use your proxy IP address on settings.xml.
  2. If you are using direct connection, delete the proxy configuration on settings.xml.

Thank you for all of my students that pointing out these errors. I hope this helps you to set up the STS workspace for Spring MVC. If you find any other errors, please let me know. You can contact me on Facebook Messenger :).

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

Advertisements

4 thoughts on “First Spring MVC project using Spring Tool Suite (STS) and Maven build

  1. Hi,
    You show us: File–> new —Spring Project, but some show us: File–>new–Maven Project.
    When doing your way, STS will include all POM file, views folder…but on Maven Project, we have to do that manually. Why another(I will say another programmer) won’t use new–>Spring Project, but they use Maven Project then take time to fill out those POM file or views folder?
    Thank you very much!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s