[antlr-interest] TestRig: use with package-ized lexer/parser?

Graham Wideman gwlist at grahamwideman.com
Mon Nov 12 21:11:59 PST 2012


... and a solution to the outstanding NetBeans (possibly other IDEs) problem: How to supply an application launched from NetBeans IDE with a particular current working directory, _and_ classpath that includes that cwd.  

This is needed to run/debug TestRig (or custom version thereof), which relies on cwd to find the lexer/grammar classes and dynamically load them. 

Basically, this requires

a) the IDE setting for the runtime working directory is set to the directory containing the grammar classes (or the root of their class directory tree, if using packages), and...

b) include "current working directory" in the IDE-constructed runtime classpath.

But how to accomplish (b)?

The trick is to include the Ant/NB variable work.dir in the list of runtime libraries.  There doesn't seem to be a way to set this up from the NetBeans UI, but it can be accomplished by hand editing project.properties run.classpath item, similar to the following:

run.classpath=\
    ${javac.classpath}:\
    ${build.classes.dir}:\
    ${work.dir}

Presumably also applies to run.test.classpath.

The result of this is that when NB/Ant invokes java to run the program, NB/Ant assembles a classpath that includes the current working directory setting. 

And FWIW, this can be examined by setting NetBeans Tools > Options > Java > Ant tab > Verbosity Level to Verbose (which displays the runtime java command line in the Output window).

-- Graham



More information about the antlr-interest mailing list