Debugging to a remote Payara 5 Server

I am trying to debug a Java EE/Jakarta EE with NetBeans 12 and Gradle 7.5. I know how to call a task for debugging purposes from NetBeans.

I can create a task to call from NetBeans to debug a regular Java app. I am having trouble when I have to debug an application deployed to a remote Payara server, I am not sure how to do it. The project is a war project.

task (deploy, dependsOn: 'war', type:Exec) {
    // Variable glassfishHome defined in gradle.properties
    workingDir "${glassfishHome}${File.separator}bin"

    if (System.properties['os.name'].toLowerCase().contains('windows')) {
        commandLine 'cmd', '/c', 'asadmin.bat'
    } else {
        commandLine "./asadmin"
    }

    args "deploy", "--force=true", "${war.archivePath}"   
}

task(debug, dependsOn: 'deploy', type: JavaExec) {
    // Open this page in the browser
    doLast {
        System.out.println(String.format("Classpath: %s", sourceSets.main.runtimeClasspath))
        System.out.println(String.format("Main: %s", sourceSets.main))
        // Where do I put me server address (like my.server.com:9009)?
        mainClass = // what do I put here
        classpath = // what do I put here
//        debug true
        debugOptions {
            enabled = true
            port = 9009
            server = true
            suspend = true
        }

        // turn off the broken dpi on my highDPI display.
        jvmArgs = ["-Dsun.java2d.dpiaware=false"]
        // launch the browser with the app location.
        java.awt.Desktop.desktop.browse "https://${appHttpsHost}/myApp?myParam1=this&myParam2=that".toURI()
        
    }
}

I’m not sure how you think this might be at all Gradle related.
At the point where you deployed your war to the Payara server and want to debug it, Gradle is not at all in the loop anymore.
Check in the documentation of Payara how to enable attaching a remote debugger to it and then attach your IDE to it.
This does not seem in any way Gradle related to me.

I was hoping for something similar to the following code that debugs a local running application.

task(debug, dependsOn: 'classes', type: JavaExec) {
    System.out.println(String.format("Classpath: %s", sourceSets.main.runtimeClasspath))
    System.out.println(String.format("Main: %s", sourceSets.main))
    mainClass = mainClassName
    classpath = sourceSets.main.runtimeClasspath
    debug true
    args = ["0","http://localhost:8080/myApp"]
    jvmArgs = ["-Dsun.java2d.dpiaware=false "]
}

NetBeans can be setup to call this when you want to debug your application. I click the debug button and this task is called starting a debug session.

With that task, you start your application with debug option, and then attach your IDE to it.
What you want to do is, to start Payara with debug option, and then attach your IDE to it.
Again, Gradle is out of the loop here, because you do not use Gradle to start your application, but Payara.

With that task when I press debug, NetBeans runs Gradle with:

JAVA_HOME="C:\dev\java\Java"
cd ...\myMainApp\myApp; ...\gradle\gradle-7.5\bin\gradle.bat --configure-on-demand -x check debug

I trimmed the actual directories down. Maybe I need to move this to a NetBeans forum. Thank you for your assistance.

Again, it does not use Gradle “to debug”.
Gradle just starts your application with JVM debugging enabled, then your IDE attaches to that.
You do not need a NetBeans forum, you need a Payara forum that tells you how to enable remote debugging and then maybe a NetBeans forum that tells you how to attach to the listening debugger port on the server.