R
Robert Dodier
Hello,
I am working with two examples of using the JavaCompiler class in JDK
6:
http://groups.google.com/group/comp.lang.java.programmer/msg/0243d70fbce78e52?dmode=source&hl=en
http://groups.google.com/group/comp.lang.java.programmer/msg/3265954fdaac103e?dmode=source&hl=en
I find that, after making just a few minor modifications
(JavaCompilerTool --> JavaCompiler, getResult --> call,
getStandardFileManager(diagnostics) -->
getStandardFileManager(diagnostics, null, null))
the examples run as expected. (The JavaCompiler stuff has changed
since the examples were written.) Thanks very much to the authors.
I can also modify the source code strings so that functions
such as Math.sin or Math.exp are called, and these work as expected.
However, I find that when I try to call some method which I wrote
(e.g. with FOOBAR defined as public class FOOBAR { public FOOBAR () {}
public double FOO (double x) { return x*x; }}, I try FOOBAR f = new
FOOBAR ();
f.FOO(2.0); in the source code string) then the compilation fails with
"cannot find symbol
symbol : class FOOBAR"
which is disappointing.
I tried specifying the classpath in different ways -- e.g. -cp . or
-Xbootclasspath/a:. or -cp FOOBAR.jar (after putting FOOBAR.class into
a jar file) or export CLASSPATH=. but none of those help java find
FOOBAR.
If I cut-n-paste the source code into a file, and compile it on the
command
line, then it works OK.
I wonder if anyone has some words of wisdom here.
Thanks in advance for your help.
Robert Dodier
I am working with two examples of using the JavaCompiler class in JDK
6:
http://groups.google.com/group/comp.lang.java.programmer/msg/0243d70fbce78e52?dmode=source&hl=en
http://groups.google.com/group/comp.lang.java.programmer/msg/3265954fdaac103e?dmode=source&hl=en
I find that, after making just a few minor modifications
(JavaCompilerTool --> JavaCompiler, getResult --> call,
getStandardFileManager(diagnostics) -->
getStandardFileManager(diagnostics, null, null))
the examples run as expected. (The JavaCompiler stuff has changed
since the examples were written.) Thanks very much to the authors.
I can also modify the source code strings so that functions
such as Math.sin or Math.exp are called, and these work as expected.
However, I find that when I try to call some method which I wrote
(e.g. with FOOBAR defined as public class FOOBAR { public FOOBAR () {}
public double FOO (double x) { return x*x; }}, I try FOOBAR f = new
FOOBAR ();
f.FOO(2.0); in the source code string) then the compilation fails with
"cannot find symbol
symbol : class FOOBAR"
which is disappointing.
I tried specifying the classpath in different ways -- e.g. -cp . or
-Xbootclasspath/a:. or -cp FOOBAR.jar (after putting FOOBAR.class into
a jar file) or export CLASSPATH=. but none of those help java find
FOOBAR.
If I cut-n-paste the source code into a file, and compile it on the
command
line, then it works OK.
I wonder if anyone has some words of wisdom here.
Thanks in advance for your help.
Robert Dodier