Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compileing with ant - classpath not set

Posted on 2003-10-30
4
Medium Priority
?
2,848 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

636 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