Link to home
Start Free TrialLog in
Avatar of MarteJ
MarteJ

asked on

Compileing with ant - classpath not set

Hi,

I'm new to ant. When running a specific target ( <target name="settings">) which prints out some parameters in the file (no compilation), the whole file is obviously checked for errors. The building fails:

 taskdef class com.sun.tools.xjc.XJCTask cannot be found

This is the part that creates the error (JAXB specific):

<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
    </taskdef>
    <target name="jaxbcodegeneration">
        <!-- generate the Java content classes from the schema file-->
        <echo message="Compiling the schema file..."/>
        <xjc schema="${bsl.src}/schema.xsd" target="${bsl.src}" package="somedir.jaxbcode"/>
    </target>

If I do setenv CLASSPATH to the neccesary path for com.sun.tools.xjc.XJCTask, then running 'ant settings' works fine.

The reason is that the classpath is not set until a later state in the building process (before the compilation starts). How can I set the classpath in the build.xml file (don't want to do it manually), to avoid this error. Is calling another xml file with the elements above from within this build.xml a better solution. What is the syntax for that?

Thanks for any help!!
Avatar of vk33
vk33

Hi!

You can specify your classpath in build.xml like this:

<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath>
<pathelement location="lib/jaxb.jar"/>
</classpath>
</taskdef>

Replace pathelement with something appropriate and it should work.

Good luck!
One more suggestion.
<property name="classpath" location="your_classes_location"/>
...
<classpath>
     <pathelement path="${classpath}"/>
</classpath>
...

Regards!
ASKER CERTIFIED SOLUTION
Avatar of savalou
savalou

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MarteJ

ASKER

Thank you both for taking the time to help me!!! Everything compiles now!
Sorry vk33, I didn't get your code to work.