In this chapter, we are going take a look at how we can create a basic Spring MVC application. In order to develop a Spring MVC application, we need some prerequisite software and tools. First, we are going to see how to install all the prerequisites that are required to set up our development environment so that we can start developing the application.
The setup and installation steps given here are for Windows 10 operating systems, but don't worry, as the steps may change only slightly for other operating systems. You can always refer to the respective tools and software vendor's websites to install them in other operating system. In this chapter, we will learn to set up Java and configure the Maven build tool, install the Tomcat web server, install and configure the Spring Tool Suite, and create and run our first Spring MVC project.
Obviously, the first thing that we need to do is to install Java. The more technical name for Java is Java Development Kit (JDK). JDK includes a Java compiler (javac), a Java virtual machine, and a variety of other tools to compile and run Java programs.
We are going to use Java 8, which is the latest and greatest version of Java, but Java 6 or any higher version is also sufficient to complete this chapter, but I strongly recommend you use Java 8 since in later chapters of this book we may use some of the Java 8 features such as, streams and lambda expressions. Let's take a look at how we can install JDK on a Windows operating system:
C:Program FilesJavajdk1.8.0_60
.After installing JDK, we still need to perform some more configurations to use Java conveniently from any directory on our computer. By setting up the environment variables for Java in the Windows operating system, we can make the Java compiler and tools accessible from anywhere in the file system:
JAVA_HOME
as the variable name and enter the installed JDK directory path as the variable value; in our case, this would be C:Program FilesJavajdk1.8.0_91
. If you do not have proper rights for the operating system, you will not be able to edit System variables; in that case, you can create the JAVA_HOME
variable under the User variables panel.%JAVA_HOME%in
as the value.If you are using a Windows operating system prior to version 10, edit the path variable carefully; you should only append the text at the end of an existing path value. Don't delete or disturb the existing values; make sure you haven't missed the ;
(semi-colon) delimited mark as the first letter in the text that you append:
Now we have installed JDK in our computer. To verify whether our installation has been carried out correctly, open a new command window, type java -version
, and press Enter; you will see the installed version of Java compiler on the screen:
C:UsersAmuthan>java -version java version "1.8.0_91" Java(TM) SE Runtime Environment (build 1.8.0_91-b15) Java HotSpot(TM) 64-Bit Server VM (build 25.91-b15, mixed mode)