You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jay Glanville <di...@nortelnetworks.com> on 2000/12/04 15:27:05 UTC

Having a problem with the classpath passed to task

I am trying to compile my source code to a target 1.1 VM.  The compilers I
like to use are Jikes and javac 1.3.  My problem is that when I use the
<javac> task in conjunction with a 1.3 runtime environment, the tools.jar
file gets included in the classpath if I'm using the modern compiler, and
tools.jar and rt.jar if I'm using the jikes compiler.  This is the major
reason that I cannot use Ant in my build environment.

As you can see by my included build.xml below, I'm using the bootclasspath,
extdirs and target attributes required by the compilers to ensure that my
code gets compiled against the 1.1 libraries.  However, as you can see from
the output of Ant (I've included output from both the modern compiler and
the jikes compiler) that tools.jar gets included in my classpath.

Why is this a big concern for me?  What happens if one of the designers
accidentally uses a Collection object in their sourcecode?  the loadbuild
would go through without any problems.  However, when the client was running
that class on their 1.1 virtual machine, a "class not found exception" would
be thrown when the JRE came across the Collection object.

Is there anything I can do to solve this problem (excluding having to use a
<exec> task) ?

While I'm on the subject of unwanted stuff in the classpath, is there any
way that I can get rid of the ant libraries?  I know that there is very
little chance of namespace collisions, or any other worries.  But it would
be nice to simply have the following as an execution line: jikes -d
F:\test\classes -classpath
C:\jdk\1.1.8\lib\classes.zip;F:\test\classes;F:\test\src



Thanks,
Jay

PS:  How to I set the value of extdirs to be ""?




The following is the output of an "ant -verbose" command where
build.compiler=jikes:
--->8--------------------------------------------------------------
F:\test>ant -verbose
Ant version 1.2alpha3 compiled on October 11 2000

Searching for build.xml ...
Searching in F:\test
Buildfile: F:\test\build.xml
Detected Java Version: 1.3
Detected OS: Windows NT
Project base dir set to: F:\test
Build sequence for target `default_target' is [default_target]
Complete build sequence is [default_target]
    [javac] Compiling 3 source files to F:\test\classes
    [javac] Using jikes compiler
    [javac] Compilation args: jikes -d F:\test\classes -classpath
C:\jdk\1.1.8\lib\classes.zip;F:\test\classes;F:\bin\jakarta-ant\lib\jaxp.jar
;F:\bin\jakarta-ant\lib\parser.jar;F:\bin\jakarta-ant\lib\ant.jar;F:\bin\jak
arta-ant\lib\loadbuild.jar;C:\jdk\1.3.0\lib\tools.jar;C:\jdk\1.3.0\jre\lib\r
t.jar;F:\test\src
    [javac] Files to be compiled:
    F:\test\src\A.java
    F:\test\src\B.java
    F:\test\src\C.java


BUILD SUCCESSFUL

Total time: 4 seconds
--->8--------------------------------------------------------------







The following is the output of an "ant -verbose" command where
build.compiler=modern:
--->8--------------------------------------------------------------
F:\test>ant -verbose
Ant version 1.2alpha3 compiled on October 11 2000

Searching for build.xml ...
Searching in F:\test
Buildfile: F:\test\build.xml
Detected Java Version: 1.3
Detected OS: Windows NT
Project base dir set to: F:\test
Build sequence for target `default_target' is [default_target]
Complete build sequence is [default_target]
    [javac] Compiling 3 source files to F:\test\classes
    [javac] Using modern compiler
    [javac] Compilation args: -d F:\test\classes -classpath
F:\test\classes;F:\bin\jakarta-ant\lib\jaxp.jar;F:\bin\jakarta-ant\lib\parse
r.jar;F:\bin\jakarta-ant\lib\ant.jar;F:\bin\jakarta-ant\lib\loadbuild.jar;C:
\jdk\1.3.0\lib\tools.jar -sourcepath F:\test\src -target 1.1 -bootclasspath
C:\jdk\1.1.8\lib\classes.zip -extdirs
    [javac] Files to be compiled:
    F:\test\src\A.java
    F:\test\src\B.java
    F:\test\src\C.java


BUILD SUCCESSFUL

Total time: 1 second
--->8--------------------------------------------------------------


The following is my sample build.xml
--->8--------------------------------------------------------------
<project name="TestProject" default="default_target" basedir="." >
  <property name="build.compiler" value="modern" />
  <target name="default_target" >
    <javac srcdir="src" 
        destdir="classes" 
        includes="**/*.java"
        classpath=""
        bootclasspath="c:/jdk/1.1.8/lib/classes.zip"
        extdirs=""
        target="1.1" />
  </target>
</project>
--->8--------------------------------------------------------------


----------------------------------------------------------------------------
-----
Jay Dickon Glanville
P068 - SiteManager Development, Nortel Networks
613-765-1144 (ESN 395-1144)
MS: 045/55/A05
E-Mail: dickon@nortelnetworks.com


Re: Having a problem with the classpath passed to task

Posted by Stefan Bodewig <bo...@apache.org>.
Jay Glanville <di...@nortelnetworks.com> wrote:

> I am trying to compile my source code to a target 1.1 VM.  The
> compilers I like to use are Jikes and javac 1.3.  My problem is that
> when I use the <javac> task in conjunction with a 1.3 runtime
> environment, the tools.jar file gets included in the classpath if
> I'm using the modern compiler, and tools.jar and rt.jar if I'm using
> the jikes compiler.  This is the major reason that I cannot use Ant
> in my build environment.

This is a known problem and you'll probably have attributes in <javac>
to suppress this behavior in Ant 1.3.

> Is there anything I can do to solve this problem (excluding having
> to use a <exec> task) ?

As a workaround, write your own implementation of Javac, a very simple
and untested idea:

public class MaJavac extends Javac {
    protected Path getCompileClasspath(boolean addRuntime) {
        return super.getCompileClasspath(false);
}

This will suppress rt.jar even when compiling with Jikes. You can copy
what Javac's getCompileClasspath does and omit the line

        classpath.addExisting(Path.systemClasspath);

to get rid of tools.jar as well.

At the top of your buildfile say

<taskdef name="javac" classname="MyJavac" />

and you are done.

> While I'm on the subject of unwanted stuff in the classpath, is
> there any way that I can get rid of the ant libraries?  I know that
> there is very little chance of namespace collisions, or any other
> worries.  But it would be nice to simply have the following as an
> execution line: jikes -d F:\test\classes -classpath
> C:\jdk\1.1.8\lib\classes.zip;F:\test\classes;F:\test\src

Yes, the second option above (omitting Path.systemClasspath) should do
that as well.

You could as well add options to (1) omit the runtime libraries and
(2) omit the CLASSPATH Ant has been invoked with to Javac, make the
modifications necessary to getCompileClasspath and contribute the
patch so you will see this feature in CVS sooner 8-).

Stefan