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.
If you already have a project setup and ready to deploy to Payara Server, then 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.
- 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 'payara41' directory. This is the place where you extracted Payara Server.
6. The application server field is now filled with 'GlassFish 220.127.116.11'. To change this, click on 'Configure' again, and enter the name of the server. For this, I've called it: 'Payara 18.104.22.168'. Click OK.
7. Set the name of the run configuration.
Since this is a mapping of the project 'PayaraExample' and Payara Server version 22.214.171.124, I've named the configuration: 'PayaraExample - Payara 126.96.36.199'.
8. 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. There should now be a new error. 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 artefact. Select the war file created from 'PayaraExample'. This will now build the project before deploying it to Payara Server.
10. Check that the configuration now matches the one shown below.
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 188.8.131.52' ". 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 184.108.40.206'.
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!