Make sure that the scope is provided, because the servlet container that we use to run our project will provide this dependency. This is because the jsp-api is not required when compiling your project, it is only needed when you run the project (aka it is a runtime dependency).

For me, this error came up in STS (which is a variation of Eclipse), but you can expect it in other IDEs as well.

EGit is a popular plugin to use when you would like to add support for git repositories in your project. It has a great number of features. It enables you to see changes compared to your last commit, view the history of a file, commit your changes, fetch new commits from a remote repository and so on.

It is definitely a really useful plugin, but you may not need it in every project (for example because you like using some other, external tool for managing you git repository). In STS (Spring Tool Suite) this plugin is installed by default. But disabling the git functionality can speed up the IDE.

How to disable git support

If you don’t want to use the functionality of this plugin for a project, you can disable it using the following:

Maven archetypes make it easy to create a base structure for some common Java applications. In this tutorial I am going to show you how to get a simple Java web application up and running in just a few minutes.

Creating the project

In STS select File > New > Other… or just press Crtl + N. In the wizard search for maven and select Maven Project.

In the next window make sure you leave Create a simple project (skip archetype selection) unchecked as we want to create the project using an archetype. Below this option you can specify if you would like the project to be in the default workspace location or somewhere else. Both is fine, just remember which directory your project is in.

Clicking next again will take you to the archetype selection window. In the filter field type webapp and from the filtered list choose the one that has maven-achetype-webapp as it’s artifact id.

As the last step, fill in the desired parameters for the archetype. If want your app to be accessible from the same URL as in the example, please use the artifact id seen on the screenshot below.

Finally click Finish to create the project. A new Maven project is created for you with all the necessary files and folders for a basic web application.

Running the project

To open this web application in a browser you need an application server (e.g. Tomcat). Luckily with Maven’s Tomcat plugin you don’t need to install the server manually because Maven will automatically download an instance of it for you. You can set additional configuration options in the pom.xml for the server, but for this simple example this is not necessary.

To run this project navigate to the project’s directory in the command line and issue the following command:

mvn clean install tomcat:run

This will compile the project and install it in your local Maven repository and also deploy it to the Tomcat server. The server by default starts on the 8080 port. You can access the application by typing http://localhost:8080/simple-maven-webapp/ in your browser. The last part of this URL is in this case the same as the artifact id. This is because Maven automatically generated a pom.xml for you and set the <finalName> tag to the value of the artifact id.

<build>
<finalName>simple-maven-webapp</finalName>
</build>

Note: There are other ways to change the url under which your application is available, but if you don’t specify anything else, the finalName will be used.

Eclipse and STS are both great IDEs for Java developers. STS stands for Spring Tool Suite and it’s basically an Eclipse that is extended with plugins specifically for development using the Spring framework. Knowing the useful shortcuts can really speed up the coding process. The key combinations presented here are the default ones that come with a fresh install of these tools. Here are some of the most useful ones:

Indent lines: Crtl + I

Click anywhere in a file and pressing this shortcut will indent the lines properly.

Delete current line: Crtl + D

Just move the cursor to the line that you would like to delete and press Crtl + D.

Autocomplete: Crtl + Space

Just start writing any code and press Crtl + Space to get a list of possible variable, field, method, class etc. names that are available at that point.

Rename: Alt + Shift + R

This shortcut opens the rename window for the element that is currently selected, or where you cursor currently is.

Go To Line Number: Crtl + L

This shortcut can come in very useful if you just read a stack trace that told you which line is to be blamed for the exception. Open the file in question, hit Crtl + L, type in the line number and you are immediately taken to the proper row.

Insert blank line after current line: Shift + Enter

Inserts a blank line after the current line. It does not matter where the cursor is, it can even be in the middle of the line. After the insertion the cursor will be at the beginning of the new line.

Insert blank line before current line: Shift + Enter

Inserts a blank line before the current line. It does not matter where the cursor is, it can even be in the middle of the line. After the insertion the cursor will be at the beginning of the new line.

Add / remove single line comments: Crtl + Shift + C

With this shortcut you can add / remove single line comments for the current line or all of the selected lines. When you are commenting multiple lines be careful and always select lines that are all either commented out or not commented out. If you mix these two then you might not get the expected result.

Copy current line below: Crtl + Alt + Down arrow

Very handy shortcut if you have a line of code and need one that is very similar to it. Just stand on the line and hit Crtl + Alt + Down arrow to have a copy of it below it’s current location.

Copy current line above: Crtl + Alt + Up arrow

Same as the previous one but it copies the line above the current line.

Organize import statements: Crtl + Shift + O

Organizes the import statements by removing the unused ones and adding the missing ones. This shortcut also sorts the imports alphabetically.

Format code: Crtl + Shift + F

Formats the selected code block or the whole source file. If some code is selected in the source file, only that part gets formatted. If no selection is made, the whole source file is formatted.