Build a Java application in Visual Studio Code


For years, Java development has been dominated by the big three IDEs: Eclipse, InelliJ IDEA, and NetBeans. But we have other good options. Among the large field of generalized, polyglot code editors that have been gaining mindshare, Visual Studio Code has become a standout, and offers impressive Java support. VS Code also delivers first-class support of other technology stacks including front-end JavaScript frameworks, Node.js, and Python.

Should Visual Studio Code be your next Java IDE? This article gives an introduction to using Visual Studio Code to build an enterprise Java back end with Spring and connect it to a Svelte JavaScript front end.

Set up Spring Boot

To build along with this tutorial, you will need to have Java and Maven installed. You will also need the latest Visual Studio Code distribution for your system, if you don’t already have it. It is a simple install process.

Now let’s jump right in with a new project. You are going to use Spring Initializr to create a new Spring Boot Web app. Open VS Code and click the extensions icon on the bottom left. This will let you search for available add ons (and there are a lot of them). Type in “spring init” and you’ll see the Spring Initializr Java Support extension. Install it as seen in Figure 1.

Figure 1. Installing the Spring Initializr extension

vscode java spring init IDG

Figure 1.

Once installed (it won’t take long), you can use it via the command palette, which is accessible with Ctrl-Shift-P (or View -> Command Palette from the main menu). With the command palette open, type “spring init” and you’ll see the newly installed command. Run it.

Now follow along with the wizard. You can accept most defaults like language Java; Java Version 12; artifact id “demo”; group id “com.infoworld”; packaging “JAR”; and the rest. When adding dependencies, add Spring Boot Web and Spring DevTools. (You can add more dependencies later by right-clicking the POM file and selecting “add starters.”) You’ll also select a location for the project; just select a convenient spot on your local drive.

Copyright © 2021 IDG Communications, Inc.



Source link