0

我有一个 Java 项目,它依赖于从一组企业 XML 模式中生成的一组 JAXB 类。到目前为止,我一直在通过命令行使用 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 build 任务时,它没有重建我的 JAXB。

4

1 回答 1

0

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

/*
 * 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'
}
于 2016-07-22T15:43:03.757 回答