Add Payara Server 5 to the Visual Studio Code Tutorial

Photo of Gaurav Gupta by Gaurav Gupta

In this tutorial, I will explain how to add the Payara Server in the Visual Studio Code and deploy the maven web application to the Payara Server.

Prerequisite VSCode Extensions

Before going through this tutorial, you must install the following extensions from the Visual Studio Code marketplace:

You can install extensions from Extensions view (Ctrl + Shift + X) in the activity bar of VS Code:

extensions screen shot

Creating a Web Application

Maven is the most widely used project build and dependency management tool in the Java ecosystem. So in this tutorial we will generate a Maven Web Application through the Maven archetypes and deploy the application to the Payara Server. You may also follow the same deployment procedure for the Gradle projects.

Let’s start:

  • Open the command pallet using Ctrl + Shift + P, type Maven and select the Create Maven Project option:
maven project screen shot
  • Or in the explorer sidebar expand Maven Projects, Select the + sign to create a Maven Project:
maven project java overview screen shot
  • Select More… option to find archetype available in remote catalog:
more to find archetype catalog screen shot
  • Search for the javaee8-essentials-archetype or you may select any other archetype:
select archetype screen shot
  • Select the destination folder, where the project folder will be generated and answer the prompts (groupId, artifactId, version etc) in the focused TERMINAL window to setup the maven project.

  • Open the Maven project folder in VS Code via File menu -> Open Folder… and select the payara-sample project folder:
file menu screen shot
  • As you can see, the project has a basic structure with src\main\java and src\main\webapp folders where you will find a PingResource.java REST endpoint class to get started:
basic structure of project screen shot

Adding Payara Server

  • Open the command pallet using Ctrl + Shift + P, type Payara and select the Add Payara Server option:
add payara server screen shot
  • Or In the explorer sidebar (or Payara activity bar), expand Payara Servers, Select the + sign to add Payara Server:
expand and add payara server screen shot
  • Select the location of your 'payara5' directory within the Payara Server installation:
Register Payara Server - Location
  • Now name the server whatever you want. For this example I've named it 'Payara-Server-5.201'. Press Enter:
Register Payara Server - Name

 

  • Finally, select a domain from the list or press the + sign to create the new domain:
Register Payara Server - Domain
  • The server is now created! You may also customize the JDK path or update the Admin Credentials by right click on the added server:
Payara Server - JDK Home
  • To start the Payara Server right click on the server in Payara Server explorer and select Start:
start payara server screen shot
  • After starting the server, you may see the server log in the OUTPUT window:
output window screen shot

Running the Payara Server Application

  • Now go to your project or rest endpoint file, right click on it and select the Run on Payara Server option. The project build will start and application will be deployed to Payara Server (Payara Server instance will be started if not running already):
run application on payara server
  • Now you should see a page (http://localhost:8080/payara-sample), eventually opened in your default browser. Enter the rest endpoint path to test the application.
test the application screenshot
  • You may also manage (undeploy/enable/disable) the deployed application by expanding the running Payara Server instance in the explorer sidebar and right click on the application:
undeploy the application
  • If you want to run custom goals, such as those inherited from Maven plugins, you can use the Maven Projects view in the explorer sidebar:
maven projects view in explorer sidebar

This is it! You now have a Visual Studio Code setup that is complete enough to handle any sort of real-world development.

Give it a try, download Payara Server

Payara Server 2020.2 Download

New to Payara Server?  Follow the Getting Started Guides

Getting Started   Video TutorialGetting Started Online Guide

 

Comments