Solved

Compileing with ant - classpath not set

Posted on 2003-10-30
4
2,680 Views
Last Modified: 2013-11-23
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!!
0
Comment
Question by:MarteJ
  • 2
4 Comments
 
LVL 4

Expert Comment

by:vk33
ID: 9650989
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!
0
 
LVL 4

Expert Comment

by:vk33
ID: 9651063
One more suggestion.
<property name="classpath" location="your_classes_location"/>
...
<classpath>
     <pathelement path="${classpath}"/>
</classpath>
...

Regards!
0
 
LVL 3

Accepted Solution

by:
savalou earned 250 total points
ID: 9651799
Take a look at a build.xml in the jaxb examples.   They do it like this.  So you need to set jwsdp.home in your build file.

    <property name="jwsdp.home" value="c:/jwsdp-1.3"/> <!-- customize this -->

    <path id="classpath">
        <pathelement path="."/>
        <!-- for use with bundled ant -->
        <fileset dir="${jwsdp.home}" includes="jaxb/lib/*.jar"/>
         <fileset dir="${jwsdp.home}" includes="jwsdp-shared/lib/*.jar"/>
       <fileset dir="${jwsdp.home}" includes="jaxp/lib/**/*.jar"/>
       
    </path>

    <taskdef classname="com.sun.tools.xjc.XJCTask" name="xjc">
        <classpath refid="classpath"/>
    </taskdef>

    <target name="compile">

        <javac debug="on" destdir="." srcdir=".">
            <classpath refid="classpath"/>
            <include name="BaseClass.java"/>
          <exclude name="Main.java"/>
        </javac>

        <!-- generate the Java content classes from the schema -->
        <echo message="Compiling the schema..."/>
        <xjc binding="binding.jxb" extension="true" package="xxx" schema="po.xsd" target="."/>
        <!-- generate the javadocs from the content classes -->
        <mkdir dir="docs/api"/>
        <javadoc destdir="docs/api" packagenames="xxx" sourcepath="." windowtitle="Generated Interfaces for po.xsd">
            <classpath refid="classpath"/>
          </javadoc>

        <!-- compile all of the java sources -->
        <echo message="Compiling the java source files..."/>
        <javac debug="on" destdir="." srcdir=".">
            <classpath refid="classpath"/>
        </javac>
    </target>
0
 

Author Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now