How to use Spring 5.0 in NetBeans 8.2?

13.1k Views Asked by At

When I create a Java Web project in NetBeans and select a Framework, in this case Spring Web MVC, only two options appear:

  • Version 4.0.1
  • Version 3.2.7

enter image description here

3

There are 3 best solutions below

4
On BEST ANSWER

You can do this in Netbeans:

  1. Download the Spring Framework you need from here

  2. Extract the contents of the archive and copy the contents of the lib directory to your netbeans location e.g /home/stanley/netbeans-8.2/java/modules/ext/spring-(version) e.g 5.1.4

  3. On your netbeans go to Tools > Libraries > New Library

  4. Name your Library as Spring Framework (version) e.g 5.1.4 and add all the jars from the location in 2 above. enter image description here

  5. Restart your netbeans application.

You should have the new Framework as shown in the diagram below: enter image description here

6
On

TL;DR

The easiest way to create a new spring project is using Spring Initializr. All you need to do is fill in the form, download the project, unzip it and open in NetBeans.

Explanation

Regardless of a language and IDE, it is usually good idea to create a new project based on a standard build-tool for the language's ecosystem and avoid creating an IDE-specific project. That makes it easier to share the project with people who use a different IDE and switch your IDE in the middle of the project.

There are several build-tools for Java ecosystem but I'd suggest to pay attention to two of them: Maven and Gradle. Those are most widespread and supported by IDEs.

NetBeans supports Maven out of box. It supports Gradle too but in 8.2 you are supposed to install a support plugin for Gradle (from Tools -> Plugins menu).

You can generate a new Maven or Gradle project using NetBeans. Select corresponding menu item when selecting the type of the project.

New Project dialog

Then you will have to add the dependencies of the project to its descriptor (pom.xml for Maven or build.gradle for Gradle). See the documentation for the build-tool of your choice to understand how exactly to do that.

Spring provides Spring Initializr service to generate a new project based on spring's libraries. It is the easiest way for a quick start.

0
On

Since you are using Netbeans and it supports Maven out of the box, you can get an existing Maven archetype to setup a basic Spring application for you to start from.

Although there isn't any official archetype, there are a lot of really nice 3rd party ones like https://github.com/kolorobot/spring-mvc-quickstart-archetype

The steps to start a new project are quite fast and straight forward (Netbeans 11)

File -> New Project -> Java with Maven -> Project from archetype

In the search filter enter spring-mvc-quickstart-archetype, enter your project details and click Finish