How to execute the JAXB compiler from ANT

前端 未结 3 1596
滥情空心
滥情空心 2020-12-16 13:45

I am using JAXB on a project. the attraction of JAXB is that it is bundled with the JDK, I have been to use xjc.exe on the command line to generate the .java files from a sc

相关标签:
3条回答
  • 2020-12-16 14:00

    Here is a helpful link:

    • https://jaxb.java.net/nonav/2.0.2/docs/xjcTask.html

    Java SE 6 does not ship the Ant task (see 7.1.3):

    • https://jaxb.java.net/guide/Migrating_JAXB_2_0_applications_to_JavaSE_6.html

    Essentially they do the following:

    <target name="xjc" description="....">
        <exec executable="${jdk.dir}/bin/xjc.exe">
            <arg value="-d"/>
            <arg value="${src.dir}"/>
            <arg value="-p"/>
            <arg value="com.mydomain.jaxb"/>
            <arg value="${etc.dir}/myschema.xsd"/>
        </exec>
    </target>
    
    0 讨论(0)
  • 2020-12-16 14:03

    You cant find several sample Ant/JAXB projects in JAXB2 Basics:

    http://confluence.highsource.org/display/J2B/Latest+Release

    0 讨论(0)
  • 2020-12-16 14:20
    <target name="generate-jaxb-code">
        <java classname="com.sun.tools.internal.xjc.XJCFacade">
                <arg value="-p" />
                <arg value="com.example"/>
                <arg value="xsd/sample.xsd" />
        </java>
    </target>
    

    Just went hunting in the tools.jar and found the XJCFacade.class in com.sun.tools.internal tested the above code it works it produces the output as xjc.exe It seems that XJC.exe calls this code com.sun.tools.internal.xjc.XJCFacade

    One of my key requirements was that the ant file had work within eclipse without having to include a path name to the JDK that way the file would be portable across operating systems. I am assuming that tools.jar is included on the classpath via the installed JRE preferences options.

    0 讨论(0)
提交回复
热议问题