When testing an app to be run on Payara Server, it can be extremely useful to be able to test your app continuously in your IDE (after all, that’s what it’s there for). If you're using IntelliJ IDEA, this is made very easy. Follow the steps in this blog to setup the Payara Server in IntelliJ for running your web apps. Note: Java EE support is only included in IntelliJ Ultimate Edition, so this blog will assume you are not using the Community Edition.
If you already have a project setup and ready to deploy to Payara Server, you can skip the first section. Otherwise, this section will quickly run through how to setup a project to test deploying to Payara Server.
Creating a Test Application with Maven
First, click ‘create new project’ on the welcome screen to IntelliJ IDEA.
Next, setup a Maven project from the archetype ‘maven-archetype-webapp’, as shown below. Make sure the project SDK points to the correct Java JDK you have installed.
3. After clicking next, enter an appropriate group ID, artifact ID and version. As this is just a test project, they don’t matter too much.
4. Click next through the rest of the screens, making sure the information is correct. Set a project name. For this example, I've named the project 'PayaraExample'.
5. Congratulations, you’ve got your first web app setup ready for deploying to Payara Server!
Adding Payara Server to IntelliJ IDEA
Now you’ve got your project ready to deploy, you need to set a run configuration for your project. If you haven’t used a run configuration before - don’t worry, it’s just a way of defining how your projects can be run. You can have multiple run configurations for a project if it needs to be run in multiple ways. Follow these steps to make a run configuration for your project.
Go to Run → Edit Configurations in the top menu.
You’ll see the default run configurations on the left. Add a new configuration from the green plus in the top left.
- From the templates choose GlassFish Server → Local / Remote (depending on your own environment).
- In this window, you need to define an application server for IntelliJ IDEA. Click on 'Configure' next to the application server field.
5. In the configuration window, select the location of your 'payara5' directory. This is the place where you extracted Payara Server to. You will need an extracted copy of Payara regardless of whether the Payara Server to deploy to is local or remote. This is so that the client libs are available for deployment.
6. The application server field is now filled with 'GlassFish 5.183.0'. To change this, click on 'Configure' again, and enter the name of the server. For this, I've called it: 'Payara 5.183'. Click OK.
7. Set the name of the run configuration.
Since this is a mapping of the project 'PayaraExample' and Payara Server version 5.183, I've named the configuration: 'PayaraExample - Payara 5.183'.
8. If you selected a local Payara configuration, there should be an error at the bottom of the window. This is correct, as we haven't defined a domain for using.
A domain always contains at least one server (the Domain Admin Server) which can be deployed to without any issues in development. For this example, I've used the default 'domain1'. Select this from the dropdown 'Server Domain'.
9. If instead you selected a remote Payara configuration, you will need to fill in the admin port (default 4848), admin username, admin password under 'GlassFish Server Settings' as well as the hostname and port for the application to be deployed to.
10. There should now be a new error for local configurations. Don't worry, if you've followed the steps correctly nothing's gone wrong yet! The error means that the run configuration isn't running anything on the server, so it would just start and stop Payara Server without doing anything.
To fix this, go to the 'Deployment' tab at the top, and add a new artifact. Select the war file created from 'PayaraExample'. This will now build the project before deploying it to Payara Server. This step should also be performed for remote configurations to deploy an artifact.
11. The run configuration is now complete! All that's needed now is to run the project.
To run the project, go to the 'Run' menu at the top, and select "Run 'PayaraExample - Payara 5.183' ". You'll notice that this is the name of the run configuration you just made.
This should open a server console window at the bottom and start up the server. If everything is set up correctly, a 'Hello World' message should display in your browser!
( click image to enlarge)
To stop the server, either click the red square in the bottom left server window, or go to Run → Stop 'PayaraExample - Payara 5.183'.
That's all the steps required to run Payara Server in IntelliJ IDEA. You're now free to develop web applications for deploying to Payara Server!