简体   繁体   中英

How do you debug a Gradle project with native dependencies in Netbeans?

I have a project that requires native libraries to run. I'm using the Gradle-Support Netbeans plugin.

apply plugin: "java"
apply plugin: "application"
apply plugin: "eclipse"

sourceCompatibility = 1.7

mainClassName = "com.myPackage.MainClass"

if (!project.hasProperty('mainClass')) {
    ext.mainClass = mainClassName
}

repositories {
    mavenCentral()

    maven {
        url "http://teleal.org/m2"
    }
}

dependencies {
    compile group: "com.esotericsoftware.kryo", name: "kryo", version: "2.23.0"
    compile group: "net.java.jinput", name: "jinput", version: "2.0.5"
    compile group: "org.jcraft", name: "jorbis", version: "0.0.17"
    compile group: "org.jdom", name: "jdom2", version: "2.0.5"
    compile group: "org.lwjgl.lwjgl", name: "lwjgl", version: "2.9.0"
    compile group: "org.lwjgl.lwjgl", name: "lwjgl_util", version: "2.9.0"
    compile group: "org.teleal.cling", name: "cling-core", version: "1.0.5"
    compile group: "org.teleal.cling", name: "cling-support", version: "1.0.5"
    compile group: "xpp3", name: "xpp3", version: "1.1.4c"

    compile files("./lib/jars/kryonet-2.21.jar")
    compile files("./lib/jars/slick.jar")
    compile files("./lib/jars/slick-util.jar")
    compile files("./lib/jars/TWL.jar")
}

jar {
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
        configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
    }

    manifest {
        attributes "Main-Class": project.mainClassName
    }
}

run {
    configureRun(it)
}

task(debug, dependsOn: 'classes', type: JavaExec) {
    configureRun(it)
    classpath = sourceSets.main.runtimeClasspath
}

void configureRun (def task){
    main = mainClass
    task.systemProperty "java.library.path", "./lib/native/"
}

The application will launch fine in run mode but debug mode yields the following error:

 FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':debug'.
> No main class specified

I assume, you are using the application plugin and that is why this configuration for the run task is enough. That is, most likely you should have something like this:

if (!project.hasProperty('mainClass')) {
    ext.mainClass = mainClassName
}

run {
    configureRun(it)
}

task(debug, dependsOn: 'classes', type: JavaExec) {
    configureRun(it)
    classpath = sourceSets.main.runtimeClasspath
}

void configureRun(def task) {
    main = mainClass
    task.systemProperty "java.library.path", "./lib/native/"
}

task(debug, dependsOn: 'classes', type: JavaExec) {

Looks like you're adding an action instead of configuring the the task, all your configuration on the task happens too late, that is at the execution time.

Either that or make sure your main (you must have one somewhere, right? I'm new to this) looks like:

public static void main (String[] args)throws Exception

My research led me to here: (this site may help you with gradle) http://forums.gradle.org/gradle/topics/problem_with_javaexec

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM