Solved

Compileing with ant - classpath not set

Posted on 2003-10-30
4
2,708 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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.

825 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