ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject FW: classpathref weirdness
Date Thu, 03 May 2001 13:07:59 GMT

I originally posted this to ant-user and got no response. Perhaps it's 
more of an ant-dev question, so here goes...

I'm having a problem using a classpathref for both compilation and 
execution. It appears to work properly for the former but not the 
latter, even though it's the exact same refid. I'm hoping this is due 
to a bug in Ant, and not just my own ignorance. Here's the 

I have a simple directory setup...

 build.bat # sets ANT_HOME, JAVA_HOME (1.2), CLASSPATH, starts ant
 build.xml # defines paths, compilation and run targets
  jndi.jar         # JNDI 1.2.1 (
  ldap.jar         # LDAP SP 1.2.2
  providerutil.jar # LDAP SP 1.2.2
 /src # attempts to get an InitialDirContext refers to classes both statically and dynamically in the jar 
files. The compilation executes without fail, but the execution of fails with the following...

javax.naming.NoInitialContextException: Cannot instantiate class: 
com.sun.jndi.ldap.LdapCtxFactory [Root exception is 
java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory]

...even though the class does in fact exist in ldap.jar. 

Note: This problem isn't specific to JNDI, as I observed similar 
behavior in a more trivial example. The use of JDK 1.2 here is 
significant, as it does not include JNDI/LDAP support natively. When 
using JDK 1.3, this problem does not occur. Also, unless you edit the file to refer to a valid LDAP server, success would actually 
look like an host not found error.

Here are listings of the specific files...

----- begin build.bat -----
@echo off

set JAVA_HOME=C:\Programs\jdk1.2.2
set ANT_HOME=C:\Programs\jakarta-ant-1.3

set PATH=%PATH%;%ANT_HOME%\bin

ant -buildfile build.xml %1
----- end build.bat -----

----- begin build.xml -----
<project name="antbug" default="test" basedir=".">

  <property name="src" value="src"/>
  <property name="classes" value="classes"/>

  <path id="lib.class.path">
    <fileset dir="lib">
      <include name="**/*.jar"/>

  <path id="classes.class.path">
    <pathelement location="classes"/>

  <path id="project.class.path">
    <path refid="lib.class.path"/>
    <path refid="classes.class.path"/>

  <target name="compile">
    <mkdir dir="${classes}"/>
    <javac classpathref="project.class.path" 
     srcdir="${src}" destdir="${classes}"/>

  <target name="test" depends="compile">
    <java classpathref="project.class.path" classname="Test"/>

  <target name="clean">
    <delete dir="${classes}"/>

----- end build.xml -----

----- begin -----
import java.util.*;
import javax.naming.*;

public class Test {

  public static void main(String[] args) throws Exception {

    Hashtable env = new Hashtable();


    DirContext dirCtx = new InitialDirContext(env);

----- end -----

View raw message