ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject classpathref weirdness
Date Wed, 02 May 2001 13:25:41 GMT

I'm having a problem using a classpathref for both compilation and 
execution. It appears to work properly for the former but not the 
later, 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 particulars...

I have a simple directory setup...

  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
 build.bat # sets ANT_HOME, JAVA_HOME (1.2), clears CLASSPATH, starts 
 build.xml # defines path to include jars and classes dir, compiles, 

Note: The use of JDK 1.2 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. 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. 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