如何使用Netbeans中的本机依赖项调试Gradle项目?

时间:2014-05-03 03:01:08

标签: java netbeans gradle

我有一个需要本机库运行的项目。 我正在使用Gradle-Support Netbeans插件。

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/"
}

应用程序将在运行模式下正常启动,但调试模式会产生以下错误:

 FAILURE: Build failed with an exception.

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

2 个答案:

答案 0 :(得分:1)

我假设您正在使用应用程序插件,这就是为什么运行任务的此配置就足够了。也就是说,你很可能应该有这样的东西:

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/"
}

答案 1 :(得分:0)

任务(debug,dependsOn:'classes',type:JavaExec){

看起来你正在添加一个动作而不是配置任务,任务的所有配置都发生得太晚,即执行时。

或者确定你的主要(你必须在某个地方,对吗?我是新手)看起来像:

public static void main(String [] args)抛出异常

我的研究让我来到这里:(这个网站可能会帮助你学习)http://forums.gradle.org/gradle/topics/problem_with_javaexec