Search code examples
antjavacopenjpametamodel

How do I reference the -s flag for javac in an ant script?


I am trying to compile the canonical metamodel classes for some JPA entities using an ant script. I am using OpenJPA. I would like the generated files to be located in a subdirectory which, according to the OpenJPA documentation, I can do by specifying the -s option for javac. The way I am trying to do this right now is like this:

<compilerarg value="-s c:\buildfiles"/>

However, I keep getting an error that says:

javac: invalid flag: -s 
Usage: javac <options> <source files>

If I do:

<compilerarg value="-version"/>

it tells me that I am using 1.6. And if I do:

<compilerarg value="-help"/>

it lists -s as a valid option. Does anybody have any advice on what I can do to accomplish what I'm trying to do? Thank you!


Solution

  • You have two args in there, with a space between them. You just need to separate them:

    <compilerarg value="-s"/>
    <compilerarg value="c:\buildfiles"/>
    

    At the moment you're parsing the single arg "-s c:\buildfiles". If you run

    ant -verbose
    

    you can verify this - you'll see something like:

      [javac] Compilation arguments:
        [javac] '-classpath'
        [javac] ''
        [javac] '-sourcepath'
        [javac] '/a/b/c'
        [javac] '-target'
        [javac] '1.5'
        [javac] '-g:none'
        [javac] '-s c:\buildfiles'    <-- here is the problem
        [javac] '-source'
        [javac] '1.5'
        [javac] 
        [javac] The ' characters around the executable and arguments are
        [javac] not part of the command.