Kohsuke Kawaguchi escreveu:
> Dan Kolar wrote:
>
>> Hi,
>>
>> as I've noticed, you are developer, somehow responsible for xjc
>> task.Because I can't find the answer anywhere else, I turned on you;-)
>> I have a project using xjc and jaxb2.0 in netbeans 5.5. It parse .xsd
>> schema and create appropriate jave classes via xjc, and then use them
>> to marshall data to xml from some database input.
>> But I face a serious issue (at least for me) that I can't force xjc
>> to creates these classes from .xsd, anytime I build the project.
>
I'm actually using Netbeans 5.5 too and I've changed the build script to
invoke xjc, I've put a hook on the "-post-compile" target and commented
the "depends" "produces" block and for me it's doing the trick, my build
file follows (Sorry by the portuguese comments):
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<project name="JAXBClient" default="default" basedir=".">
<description>Builds, tests, and runs the project JAXBClient.</description>
<import file="nbproject/build-impl.xml"/>
<!-- Customização do build script para execução do binding compiler -->
<!-- efetuada contra os xml schemas do octopus, a realização deste -->
<!-- processo de maneira automatizada utiliza a especificação JAXB -->
<!-- maiores referências do projeto em
https://jaxb.dev.java.net/ -->
<!-- Xmlschemas -->
<property name="xmlschemas.dir" value="./xmlschemas"/>
<property name="OctopusDbVendors.xsd"
value="${xmlschemas.dir}/OctopusDbVendors.xsd"/>
<property name="databaseConf.xsd"
value="${xmlschemas.dir}/databaseConf.xsd"/>
<property name="loaderJob.xsd" value="${xmlschemas.dir}/loaderJob.xsd"/>
<!-- Diretório JAXB -->
<property name="jaxb.dir" value="./extlib"/>
<!-- Diretório do Commons Lang -->
<property name="commonslang.dir" value="./extlib"/>
<!-- Diretório de fontes -->
<property name="source.dir" value="./src"/>
<!-- Propriedade a ser definida caso todas as condições necessárias -->
<!-- para a execução do JAXB Binding Compiler estejam satisfeitas -->
<condition property="jaxb.complete">
<and>
<available file="${xmlschemas.dir}" type="dir"/>
<!-- Diretório e arquivos .jar pertinentes ao JAXB -->
<available file="${jaxb.dir}" type="dir"/>
<available file="${jaxb.dir}/activation.jar" type="file"/>
<available file="${jaxb.dir}/jaxb-api.jar" type="file"/>
<available file="${jaxb.dir}/jaxb-impl.jar" type="file"/>
<available file="${jaxb.dir}/jaxb-xjc.jar" type="file"/>
<available file="${jaxb.dir}/jsr173_1.0_api.jar" type="file"/>
<!-- xml schemas pertinentes ao Octopus -->
<available file="${xmlschemas.dir}/OctopusDbVendors.xsd" type="file"/>
<available file="${xmlschemas.dir}/databaseConf.xsd" type="file"/>
<available file="${xmlschemas.dir}/loaderJob.xsd" type="file"/>
</and>
</condition>
<!-- Se as condições necessárias para a execução do JAXB foram -->
<!-- atendidas o classpath é definido junto com custom task do xjc -->
<target name="-post-compile" if="jaxb.complete">
<!-- Define o classpath para funcionamento da custom task -->
<path id="classpath">
<pathelement path="./src" />
<pathelement path="./build/classes" />
<pathelement path="./xmlschemas" />
<fileset dir="${commonslang.dir}" includes="*.jar" />
<fileset dir="${jaxb.dir}" includes="*.jar" />
</path>
<!-- Define a custom task para compilação do xml schema -->
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath refid="classpath" />
</taskdef>
<!-- Efetiva a compilação do xml schemas -->
<echo message="Compiling xmlschema ${loaderJob.xsd} =========="/>
<xjc package="com.softing.etl.beans" destdir="${source.dir}">
<schema file="${loaderJob.xsd}"/>
<!--<depends file="${loaderJob.xsd}"/>-->
<!--<produces dir="${source.dir}"/>-->
<arg value="-nv"/>
</xjc>
</target>
</project>
>> Usually it ends with "files are up to date
>> ", even if output directory for these classes doesn't exist. I tried
>> to change .xsd to let it recognize the difference, but this sometimes
>> works, sometimes it doesn't and I have no idea, how to make it
>> regularly. I tried removeOldOutput, but this has its drawback and
>> doesn't work either.
>> I just want xjc to do ONE thing at all: creates these java classes
>> from .xsds in specified place every time I build the project and
>> hence invoke the xjc task.
>> Is that possible??
>
I'm using it that way ;-)
>
> That's how XJC works by default --- compiles a schema every time it's
> invoked. It then has an additional feature to perform up-to-date
> checks on files to avoid unnecessary compilations.
>
> I'm not sure exactly how you are invoking XJC, but you have to find
> that out and tell it not to do an up-to-date check.
>
Regards
Marcos