Hi all,

Not sure if this is user error (suspect it's me being dumb) or an
issue in the trunk/HEAD of core.

My build works on debian, but here I'm stick on XP and for some reason
the classpath is simply not being set

I'm building a small parser and I'm using antlr.  When I compile the
code, the classpath contains antlr-3.3-complete.jar and the
compilation works (so <javac> works fine).  When I run the code using
<java>, the runtime files with org/antlr/runtime/CharStream not found.

Exactly the same build + code works fine on debian.  The differences
are: debian x64 vs windows xp 32bit, ant version (head compiled today,
vs head compiled last month) and probably update version of java.

I've tried from in eclipse, from cmd prompt and from powershell, I've
removed the classpath env variable (set by evil quicktime) - all to no
avail.  What I don't get is how the classpath works in the antlr and
compile targets but not in the run target.

It seems like such a simple classpath problem, but I have no idea why
it's not working for the <java> task

[java] java.lang.NoClassDefFoundError: org/antlr/runtime/CharStream
[java] Caused by: java.lang.ClassNotFoundException: org.antlr.runtime.CharStream
[java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[java]     at java.security.AccessController.doPrivileged(Native Method)
[java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[java] Could not find the main class: Test. Program will exit.
[java] Exception in thread "main"
[java] Java Result: 1


Trying it now independently from ant:

PS C:\workspace\antlr-test> java -classpath
.\lib\antlr-3.3-complete.jar -jar .\build\jar\antlr-test.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
org/antlr/runtime/CharStream
Caused by: java.lang.ClassNotFoundException: org.antlr.runtime.CharStream
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Test. Program will exit.
PS C:\workspace\antlr-test>

It seems that there is a classpath issue.

Any help appreciated.
Thanks,
Kev

---
<project name="antlr-test" basedir="." default="main"
xmlns:antlr="antlib:org.apache.tools.ant.antlr">
        
        <!-- properties for location of directories and files used in build -->
        <property name="src.dir" value="src" />
        <property name="gen.dir" value="gen" />
        <property name="grammar.dir" value="${basedir}/grammars" />
        <property name="build.dir" value="build" />
        <property name="classes.dir" value="${build.dir}/classes" />
        <property name="jar.dir" value="${build.dir}/jar" />
        <property name="main-class" value="Test" />
        <property name="grammar-file" value="${grammar.dir}/Expr.g" />
        <property name="test-file" value="antlrtest" />
        <property name="antlr.jar" 
value="${basedir}\lib\antlr-3.3-complete.jar"/>
        
        <!-- Path settings used for classpath and execution -->
        <path id="base.path">
                <fileset dir="${basedir}/lib">
                        <include name="antlr-3.3-complete.jar" />
                        <include name="ant-antlr3.jar" />
                </fileset>
                <pathelement location="${classes.dir}" />
        </path>
        
        <!-- define the tasks -->
        <taskdef uri="antlib:org.apache.tools.ant.antlr"
                        resource="org/apache/tools/ant/antlr/antlib.xml"
                        classpathref="base.path"/>

        <target name="clean">
                <delete dir="${build.dir}"/>
                <delete dir="${gen.dir}"/>
                <mkdir dir="${build.dir}"/>
                <mkdir dir="${gen.dir}"/>
        </target>
        
        <target name="antlr">
                <antlr:ant-antlr3 target="${grammar-file}" 
outputdirectory="${basedir}/gen">
                    <classpath refid="base.path"/>
                </antlr:ant-antlr3>
        </target>
        
        <target name="compile" depends="antlr">
                <mkdir dir="${classes.dir}" />
                <javac srcdir="${src.dir}:${gen.dir}" destdir="${classes.dir}">
                        <classpath refid="base.path" />
                </javac>
        </target>
        
        <target name="jar" depends="compile">
                <echo message="${antlr.jar}"/>
                <mkdir dir="${jar.dir}" />
                <jar destfile="${jar.dir}/${ant.project.name}.jar" 
basedir="${classes.dir}">
                        <manifest>
                                <attribute name="Main-Class" 
value="${main-class}" />
                                <attribute name="Class-Path" 
value=".;${antlr.jar}" />
                        </manifest>
                </jar>
        </target>
        
        <target name="run" depends="jar">
                <echo message="${basedir}"/>
                <echoproperties/>
                <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"
input="${test-file}">
                        <jvmarg value="-verbose"/>
                        <classpath refid="base.path" />
                </java>
        </target>
        <target name="clean-build" depends="clean,jar" />
        
        <target name="main" depends="clean,run" />
</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to