Debugging: Diagnose and Detect the Cause of Errors in your Application
Originally published on 13 Sep 2018
Last updated on 06 Sep 2019
![Photo of Gaurav Gupta](https://blog.payara.fish/hs-fs/hubfs/Gaurav.jpg?width=200&name=Gaurav.jpg)
This debugging guide will help you to diagnose and detect the cause of errors in your application by debugging Payara Server or Payara Micro.
Prerequisites : Payara NetBeans IDE Plugins Installation
1. Debugging the Application Deployed to Payara Server
If you want to debug your application deployed on Payara Server, you may start a server in the debug mode :
1.a) Using NetBeans IDE Plugin :
Adding Payara Server to NetBeans :
- Go to Tools → Servers.
- Click Add Server.
- Select Payara Server and choose a name for the server.
![image11-3](https://blog.payara.fish/hs-fs/hubfs/image11-3.png?width=351&name=image11-3.png)
- Select the location of the Payara Server.
![image12-3](https://blog.payara.fish/hs-fs/hubfs/image12-3.png?width=482&name=image12-3.png)
- Once Payara Server is added to NetBeans it can be found under Servers with the configured name. That’s how to add Payara Server to NetBeans.
![image3-7](https://blog.payara.fish/hs-fs/hubfs/image3-7.png?width=371&name=image3-7.png)
Debugging the Application :
- First, the application run settings need to be configured to use Payara Server. Go to Properties on a project and then the Run section of this window. Now select the Payara Server from Server list.
![image8-3](https://blog.payara.fish/hs-fs/hubfs/image8-3.png?width=333&name=image8-3.png)
- In the Projects window, navigate to the your project, right click and In the pop-up menu select Debug. The IDE start the Payara server in debug mode and deploys the project.
![image7-3](https://blog.payara.fish/hs-fs/hubfs/image7-3.png?width=393&name=image7-3.png)
- Now add the breakpoints in the program, trace the program execution step-by-step by evaluating the value of variables and diagnosethe problem.
![image4-4](https://blog.payara.fish/hs-fs/hubfs/image4-4.png?width=559&name=image4-4.png)
1.b) Using the Command Line :
- Alternatively you may also start the Payara Server in debug mode using the following asadmin command with --debug flag :
![image2-7](https://blog.payara.fish/hs-fs/hubfs/image2-7.png?width=570&name=image2-7.png)
- After Payara Server starts you may manually attach the debugger to your application in the NetBeans IDE. From the main menu, select Debug → Attach Debugger, enter the port value 9009 and click ok :
![image1-6](https://blog.payara.fish/hs-fs/hubfs/image1-6.png?width=523&name=image1-6.png)
2. Debugging the Payara Micro Application
If you want to debug your Payara Micro application, you may start a micro instance in the debug mode :
2.a) Using NetBeans IDE Plugin :
Creating Payara Micro Application :
- Simply start up the NetBeans IDE and then Choose File → New Project from the main menu.
- On the Choose Project panel, select Maven from Categories, select Payara Micro Application from Projects, and click Next.
![image5-4](https://blog.payara.fish/hs-fs/hubfs/image5-4.png?width=342&name=image5-4.png)
- On the Name and Location panel, enter SampleMicro as the project name, set the Project Location, set the GAV details, and then click Next.
![image14-2](https://blog.payara.fish/hs-fs/hubfs/image14-2.png?width=369&name=image14-2.png)
- Select Payara Micro version and click Finish.
![image13-2](https://blog.payara.fish/hs-fs/hubfs/image13-2.png?width=369&name=image13-2.png)
- When you click Finish, the IDE creates the project.
![image6-2](https://blog.payara.fish/hs-fs/hubfs/image6-2.png?width=530&name=image6-2.png)
Debugging the Application :
- In the Projects window, right click on the created project and select the Debug in the pop-up menu :
![image10-3](https://blog.payara.fish/hs-fs/hubfs/image10-3.png?width=358&name=image10-3.png)
- Now, the IDE starts the Payara Micro instance in debug mode :
![image4-1-3](https://blog.payara.fish/hs-fs/hubfs/image4-1-3.png?width=559&name=image4-1-3.png)
- Now add the breakpoints in the program, trace the program execution step-by-step by evaluating the value of variables and diagnosethe problem.
2.b) Using the Command line :
Creating the Payara Micro Application :
Payara Micro application can be created from command line using the following maven archetype command :
mvn archetype:generate -DarchetypeGroupId=fish.payara.maven.archetypes -DarchetypeArtifactId=payara-micro-maven-archetype -DarchetypeVersion=1.0.1 -DgroupId=fish.payara.micro -DartifactId=micro-sample -Dversion=1.0-SNAPSHOT
Maven will ask for the project detail confirmation. Press enter or press Y and Maven will start generate the Payara Micro project.
Debugging the Payara Micro Application :
Now open the pom.xml and update the configuration of fish.payara.maven.plugins:payara-micro-maven-plugin by adding javaCommandLineOptions config under configuration tag :
<javaCommandLineOptions> <option> <value>-Xdebug</value> </option> <option> <key>-Xrunjdwp:transport</key> <value>dt_socket,server=y,suspend=y,address=5005</value> </option> </javaCommandLineOptions>
Now you are ready to start Payara Micro instance in debug mode with the following command :
mvn package payara-micro:start
When payara-micro goals will start executing, you may manually attach the debugger to your application in the NetBeans IDE.
From the main menu, select Debug → Attach Debugger, enter the port value 9009 and click OK to connect :
![image1-1-4](https://blog.payara.fish/hs-fs/hubfs/image1-1-4.png?width=523&name=image1-1-4.png)
Now, load the project in the IDE and add the breakpoints in program to analyse the program execution.
I recommend debugging via Payara Plugins
to quickly start the debugging session in one click.
Related Posts
Running Payara Server as a Service - Added Support for systemD on Linux
Published on 19 Nov 2021
by Rudy De Busscher
3 Comments
Client Certificate Authentication Improvements in Payara Server July and September 2021 Releases
Published on 17 Sep 2021
by Rudy De Busscher
3 Comments