H
Hack Bert
Hi all,
i have to invoke javac in my java program to compile java code thts
generated on the fly. these java classes all implement an interface
called IC.
there is an invocation scenario thats part of the javac man page (on
unix) and i got this to work nicely using
String javacArguments[] = new String[1];
javacArguments[0] = sourceFileName;
com.sun.tools.javac.Main.compile(javacArguments);
and
Class compiledCode = Class.forName(className);
Constructor constructor = compiledCode.getConstructor();
instance = (IC) constructor.newInstance();
but this method has the drawback that my java source code has to be
generated into a file and the resulting .class is again on disk.
what i want to do is to compile from a string / stringbuffer / char
stream into a byte buffer that could be consumed by the
ClassLoader.defineClass(String name, byte[] b, ...)
method in order to avoid the disk io and to hide the generated java code.
has anyone out there some code,how the classes that make up the javac
can be abused to do this ? (i know that this would be absolutely
undocumented and can change anytime...)
thx.
thomas
i have to invoke javac in my java program to compile java code thts
generated on the fly. these java classes all implement an interface
called IC.
there is an invocation scenario thats part of the javac man page (on
unix) and i got this to work nicely using
String javacArguments[] = new String[1];
javacArguments[0] = sourceFileName;
com.sun.tools.javac.Main.compile(javacArguments);
and
Class compiledCode = Class.forName(className);
Constructor constructor = compiledCode.getConstructor();
instance = (IC) constructor.newInstance();
but this method has the drawback that my java source code has to be
generated into a file and the resulting .class is again on disk.
what i want to do is to compile from a string / stringbuffer / char
stream into a byte buffer that could be consumed by the
ClassLoader.defineClass(String name, byte[] b, ...)
method in order to avoid the disk io and to hide the generated java code.
has anyone out there some code,how the classes that make up the javac
can be abused to do this ? (i know that this would be absolutely
undocumented and can change anytime...)
thx.
thomas