0

I have a Java project that depends on a set of JAXB generated classes from a set of enterprise XML schemas. I have been using XJC through the command line to generate my JAXB classes up to this point, but I am now trying to integrate my xjc command into my eclipse java project using buildship. I deleted out my JAXB classes and attempted to rebuild my java project through the eclipse gradle interface. My problem is that my java keeps trying to compile before it rebuilds my JAXB classes, and that just spits out compilation errors and abends. I tried to use a JAXB plugin and now i am just trying to call out using a Groovy call in Gradle, but no luck.

Now, my GenerateJaxb task may be malformed, but I can't even get execution to get that far, so I haven't been able to test it yet!

Here is my build.gradle code:

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

Update: I was able to fix my task and now the build compiles to success, (fixed in source code above), but when I run the gradle build task it is not rebuilding my JAXB.

Anton Cagle
  • 27
  • 1
  • 4

1 Answers1

0

Finally figured it out. Hope this helps someone :)

/*
 * 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'
}
Anton Cagle
  • 27
  • 1
  • 4