Solved

Compileing with ant - classpath not set

Posted on 2003-10-30
4
2,780 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

717 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