You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Howard Burgett <Ho...@dataonair.com> on 2000/08/28 19:38:28 UTC

Basic problem using ANT

Hi All!!

I have just started using ANT and am having a problem getting it to compile
from a very basic build.xml.  My build.xml looks like:

<project name="ref" default="compile" basedir=".">
  <target name="init">
    <tstamp/>
    <property name="src" value="." />
    <property name="classes"  value="." />
  </target>

  <target name="compile" depends="init">
    <javac srcdir="${src}" destdir="${classes}"/>
  </target>

</project>

I have a single file Test1.java to compile and ANT returns me the following
exception:

Exception in thread "main" java.lang.NoClassDefFoundError:
sun/tools/javac/Main
        at org.apache.tools.ant.taskdefs.Javac.doClassicCompile(Javac.java,
Compiled Code)
        at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java, Compiled
Code)
        at org.apache.tools.ant.Target.execute(Target.java, Compiled Code)
        at org.apache.tools.ant.Project.runTarget(Project.java:681)
        at org.apache.tools.ant.Project.executeTarget(Project.java, Compiled
Code)
        at org.apache.tools.ant.Main.runBuild(Main.java, Compiled Code)
        at org.apache.tools.ant.Main.main(Main.java, Compiled Code)

The output from ant -verbose (only for the process portion if its execution)
is:

Setting ro project property: ant.file -> C:\dev\ReferenceObjects\build.xml
Setting project property: basedir -> C:\dev\ReferenceObjects
Project base dir set to: C:\dev\ReferenceObjects
 +Target: init
   +Task: tstamp
Setting project property: DSTAMP -> 20000828
Setting project property: TSTAMP -> 1336
Setting project property: TODAY -> August 28 2000
   +Task: property
Setting project property: src -> .
   +Task: property
Setting project property: classes -> .
 +Target: compile
   +Task: javac
Build sequence for target `compile' is [init, compile]
Complete build sequence is [init, compile]
Executing Target: init
Executing Target: compile
Compiling 1 source files to C:\dev\ReferenceObjects
Using classic compiler
Compilation args: [-d, C:\dev\ReferenceObjects, -classpath,
C:\dev\ReferenceObjects;C:\dev\ReferenceObjects;C:\j2sd
kee1.2.1\lib\j2ee.jar;C:\jakarta-ant\lib\ant.jar;C:\jakarta-ant\lib\parser.j
ar;C:\jakarta-ant\lib\jaxp.jar;C:\jdk1.2.2\lib\tools.jar, 
-sourcepath, C:\dev\ReferenceObjects]
Files to be compiled:
    C:\dev\ReferenceObjects\Test1.java

The class referred to in the exception (sun.tools.javac.Main) is clearly in
the tools.jar file, and the file is in the classpath above, so I am stumped.
What is this exception saying?  Have any of you seen similar problems?

Howard Burgett
Wireless ASP Division
Brience, Inc.
407-492-6155






Re: Basic problem using ANT

Posted by jeroen <j_...@hotmail.com>.
Try including your classpath directly in the javac-task.

Like this:

<property name="classpath" value="${jar.dir}/dom2.jar:
                                      ${jar.dir}/parser.jar:
                                      ${jar.dir}/jaxp.jar:
                                      c:\java\lib\tools.jar"/>  <!-- note:
tools.jar -->

<target name="compile" depends="init">
  <javac srcdir="${src}" destdir="${classes}"/>
    <classpath>
      <pathelement path="${classpath}" />
      <pathelement location="lib/helper.jar" />  <!-- for example: jar only
needed for this particular target -->
    </classpath>
</target>

Or like this:

<target name="compile" depends="init">
  <javac srcdir="${src}" destdir="${classes}" classpath="${classpath}"/>
</target>

This way you don't have clutter your CLASSPATH with project specific class
files

What version of ant are running (ant -version)?

Jeroen




----- Original Message -----
From: "Howard Burgett" <Ho...@dataonair.com>
To: <an...@jakarta.apache.org>
Sent: Monday, August 28, 2000 7:38 PM
Subject: Basic problem using ANT


> Hi All!!
>
> I have just started using ANT and am having a problem getting it to
compile
> from a very basic build.xml.  My build.xml looks like:
>
> <project name="ref" default="compile" basedir=".">
>   <target name="init">
>     <tstamp/>
>     <property name="src" value="." />
>     <property name="classes"  value="." />
>   </target>
>
>   <target name="compile" depends="init">
>     <javac srcdir="${src}" destdir="${classes}"/>
>   </target>
>
> </project>
>
> I have a single file Test1.java to compile and ANT returns me the
following
> exception:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> sun/tools/javac/Main
>         at
org.apache.tools.ant.taskdefs.Javac.doClassicCompile(Javac.java,
> Compiled Code)
>         at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java,
Compiled
> Code)
>         at org.apache.tools.ant.Target.execute(Target.java, Compiled Code)
>         at org.apache.tools.ant.Project.runTarget(Project.java:681)
>         at org.apache.tools.ant.Project.executeTarget(Project.java,
Compiled
> Code)
>         at org.apache.tools.ant.Main.runBuild(Main.java, Compiled Code)
>         at org.apache.tools.ant.Main.main(Main.java, Compiled Code)
>
> The output from ant -verbose (only for the process portion if its
execution)
> is:
>
> Setting ro project property: ant.file -> C:\dev\ReferenceObjects\build.xml
> Setting project property: basedir -> C:\dev\ReferenceObjects
> Project base dir set to: C:\dev\ReferenceObjects
>  +Target: init
>    +Task: tstamp
> Setting project property: DSTAMP -> 20000828
> Setting project property: TSTAMP -> 1336
> Setting project property: TODAY -> August 28 2000
>    +Task: property
> Setting project property: src -> .
>    +Task: property
> Setting project property: classes -> .
>  +Target: compile
>    +Task: javac
> Build sequence for target `compile' is [init, compile]
> Complete build sequence is [init, compile]
> Executing Target: init
> Executing Target: compile
> Compiling 1 source files to C:\dev\ReferenceObjects
> Using classic compiler
> Compilation args: [-d, C:\dev\ReferenceObjects, -classpath,
> C:\dev\ReferenceObjects;C:\dev\ReferenceObjects;C:\j2sd
>
kee1.2.1\lib\j2ee.jar;C:\jakarta-ant\lib\ant.jar;C:\jakarta-ant\lib\parser.j
> ar;C:\jakarta-ant\lib\jaxp.jar;C:\jdk1.2.2\lib\tools.jar,
> -sourcepath, C:\dev\ReferenceObjects]
> Files to be compiled:
>     C:\dev\ReferenceObjects\Test1.java
>
> The class referred to in the exception (sun.tools.javac.Main) is clearly
in
> the tools.jar file, and the file is in the classpath above, so I am
stumped.
> What is this exception saying?  Have any of you seen similar problems?
>
> Howard Burgett
> Wireless ASP Division
> Brience, Inc.
> 407-492-6155
>
>
>
>
>
>

RE: Basic problem using ANT

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Howard,

You need to set the JAVA_HOME environment variable to point to your JDK
installation. When you do this ant knows how to find the tools.jar file
which contains the Sun javac compiler classes. These are not normally part
of the JDK's runtime classes.

Let me know if that doesn't get you up and running.

Conor


--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au

> -----Original Message-----
> From: Howard Burgett [mailto:HowardB@dataonair.com]
> Sent: Tuesday, 29 August 2000 4:38
> To: 'ant-user@jakarta.apache.org'
> Subject: Basic problem using ANT
>
>
> Hi All!!
>
> I have just started using ANT and am having a problem getting it
> to compile
> from a very basic build.xml.  My build.xml looks like:
>
> <project name="ref" default="compile" basedir=".">
>   <target name="init">
>     <tstamp/>
>     <property name="src" value="." />
>     <property name="classes"  value="." />
>   </target>
>
>   <target name="compile" depends="init">
>     <javac srcdir="${src}" destdir="${classes}"/>
>   </target>
>
> </project>
>
> I have a single file Test1.java to compile and ANT returns me the
> following
> exception:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> sun/tools/javac/Main
>         at
> org.apache.tools.ant.taskdefs.Javac.doClassicCompile(Javac.java,
> Compiled Code)
>         at
> org.apache.tools.ant.taskdefs.Javac.execute(Javac.java, Compiled
> Code)
>         at org.apache.tools.ant.Target.execute(Target.java, Compiled Code)
>         at org.apache.tools.ant.Project.runTarget(Project.java:681)
>         at
> org.apache.tools.ant.Project.executeTarget(Project.java, Compiled
> Code)
>         at org.apache.tools.ant.Main.runBuild(Main.java, Compiled Code)
>         at org.apache.tools.ant.Main.main(Main.java, Compiled Code)
>
> The output from ant -verbose (only for the process portion if its
> execution)
> is:
>
> Setting ro project property: ant.file -> C:\dev\ReferenceObjects\build.xml
> Setting project property: basedir -> C:\dev\ReferenceObjects
> Project base dir set to: C:\dev\ReferenceObjects
>  +Target: init
>    +Task: tstamp
> Setting project property: DSTAMP -> 20000828
> Setting project property: TSTAMP -> 1336
> Setting project property: TODAY -> August 28 2000
>    +Task: property
> Setting project property: src -> .
>    +Task: property
> Setting project property: classes -> .
>  +Target: compile
>    +Task: javac
> Build sequence for target `compile' is [init, compile]
> Complete build sequence is [init, compile]
> Executing Target: init
> Executing Target: compile
> Compiling 1 source files to C:\dev\ReferenceObjects
> Using classic compiler
> Compilation args: [-d, C:\dev\ReferenceObjects, -classpath,
> C:\dev\ReferenceObjects;C:\dev\ReferenceObjects;C:\j2sd
> kee1.2.1\lib\j2ee.jar;C:\jakarta-ant\lib\ant.jar;C:\jakarta-ant\li
> b\parser.j
> ar;C:\jakarta-ant\lib\jaxp.jar;C:\jdk1.2.2\lib\tools.jar,
> -sourcepath, C:\dev\ReferenceObjects]
> Files to be compiled:
>     C:\dev\ReferenceObjects\Test1.java
>
> The class referred to in the exception (sun.tools.javac.Main) is
> clearly in
> the tools.jar file, and the file is in the classpath above, so I
> am stumped.
> What is this exception saying?  Have any of you seen similar problems?
>
> Howard Burgett
> Wireless ASP Division
> Brience, Inc.
> 407-492-6155
>
>
>
>
>
>