繁体   English   中英

如何获得Gradle Buildship以在Eclipse中成功构建我的JAXB代码?

[英]How do I get Gradle Buildship to build my JAXB code successfully in Eclipse?

我有一个Java项目,该项目依赖于一组JAXB从一组企业XML模式生成的类。 到目前为止,我一直在通过命令行使用XJC生成我的JAXB类,但是现在我正在尝试使用buildship将xjc命令集成到我的Eclipse Java项目中。 我删除了我的JAXB类,并尝试通过eclipse gradle接口重建我的Java项目。 我的问题是我的Java在重建JAXB类之前一直尝试进行编译,而这只会吐出编译错误并异常终止。 我尝试使用JAXB插件,现在我只是想在Gradle中使用Groovy调用进行调用,但是没有运气。

现在,我的GenerateJaxb任务可能格式不正确,但是我什至无法执行,因此我还无法对其进行测试!

这是我的build.gradle代码:

    //apply your plugins
    plugins {

      id "java"
    }

    repositories {
        jcenter()
    }

    dependencies {

        // The production code uses the SLF4J logging API at compile time
        compile 'org.slf4j:slf4j-api:1.7.21'
        // log4j
        compile 'log4j:log4j:1.2.17'
        // google guava library
        compile 'com.google.guava:guava:r05'

        // Declare the dependency for your favourite test framework you want to use in your tests.
        // TestNG is also supported by the Gradle Test task. Just change the
        // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
        // 'test.useTestNG()' to your build script.
        testCompile 'junit:junit:4.12'
    }

    task GenerateJaxb(type:Exec){
workingDir 'C:\\Program Files\\Java\\jdk1.8.0_73\\bin'
commandLine 'xjc.exe -d C:\\SVN\\Tibco\\Java\\branches\\SBC_Gradle\\src\\generated\\java C:\\SVN\\Tibco\\Projects\\HIPAA\\834\\trunk\\834Automation\\Schemas\\Canonical\\SBCCalculator2017.xsd -extension -p schema'
println "ran GenerateJaxb task"
    }

更新:我能够修复我的任务,现在构建可以编译成功(已在上面的源代码中修复),但是当我运行gradle构建任务时,它并没有在构建我的JAXB。

终于想通了。 希望这可以帮助某人:)

/*
 * This build file was auto generated by running the Gradle 'init' task
 */

//apply your plugins
plugins {

  id "java"
}

//This task will rebuild the generated classes in the schema directory based on the SBC calculator canonical xsd. 
task GenerateJaxb(){

//This is the argument array that will be passed to the JAXB program called xjc.exe
def argList = []
//each argument that is separated by a space must be defined as its own element within the array.
//for example, -d tells xjc that you are going to define the target directory, and in the next argument you 
//define that target directory.  Each of those space delimited pieces of text are considered separate arguments 

//the next to arguments define the target directory (-d) in which the generated files will be placed
argList << '-d'
//relative project pathing
argList << 'src\\main\\java'

//source of schema file to convert into java objects
argList << 'C:\\SVN\\Tibco\\Projects\\Schemas\\Canonical\\calculator.xsd'

//allow vendor extensions - do not strictly follow the Compatibility Rules and App E.2 from the JAXB Spec
argList << '-extension'

//the next two arguments define the java package in which to place the objects
argList << '-p'
argList << 'com.sbc.schema'

def output

//this executes your shell script
output = exec { 
    // your path needs to be set to your jdk bin directory for this to work
    commandLine = 'xjc.exe'

    //pass your arguments array
    args = argList
    }

}

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {

    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.21'
    // log4j
    compile 'log4j:log4j:1.2.17'
    // google guava library
    compile 'com.google.guava:guava:r05'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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