Hi there,
I am using a class file dynamically created using Groovy. This class
seems broken. I would like to know how to write this class to a file (
in a similar way as javac is doing I guess). I think I have to use some
tool like ASM as this functionnality does not seem is the core J2SE but
I did not find it obvious from the documentation.
Any help welcome
Thanks
Guillaume
Roedy Green - 28 Mar 2006 22:18 GMT
>I am using a class file dynamically created using Groovy. This class
>seems broken. I would like to know how to write this class to a file (
>in a similar way as javac is doing I guess).
see http://mindprod.com/jgloss/onthefly.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
gal - 29 Mar 2006 06:03 GMT
Thanks for your answer but this is not exactly what I want to do ...
Let's say I have a class object in my code that you can tell how you it
was generated ...
I want to store that class in a file ( à la javac) but I can't call
javac as I do not have
the corresponding source file.
Regards
Guillaume
Thomas Hawtin - 29 Mar 2006 07:44 GMT
> I am using a class file dynamically created using Groovy. This class
> seems broken. I would like to know how to write this class to a file (
In what way broken?
> in a similar way as javac is doing I guess). I think I have to use some
> tool like ASM as this functionnality does not seem is the core J2SE but
> I did not find it obvious from the documentation.
I assume you mean that groovy is itself dynamically creating and loading
class files, rather than your program written in groovy is doing so.
You could modify the Groovy source appropriately.
Alternatively modify java/lang/ClassLoader.java for your JDK's src.zip,
and use -Xbootclasspath/p: to use it in place of the copy in
rt.jar/classes.jsa.
(From a legal standpoint, I think you will technically need to agree to
the JRL or similar. Only avoid if you want to contribute to similar
areas in Open Source projects, despite clause III. 3. B: "Residual
Rights. You may use any information in intangible form that you remember
after accessing the Technology, except when such use violates Sun's
copyrights or patent rights." IANAL)
Perhaps some debuggers allow you to save byte arrays from programs
stopped at a breakpoint.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Chris Uppal - 29 Mar 2006 09:08 GMT
> I am using a class file dynamically created using Groovy. This class
> seems broken. I would like to know how to write this class to a file
As far as I can tell, when Groovy is working normally, it uses ASM to create
bytecode dynamically in memory, which is then passed directly to the
classloader(s). So I doubt whether it is possible to get the binary data after
that.
There is almost certainly a way to tell the Groovy system to save the
classfiles to file, since they'll need that for debugging the code generator,
but I don't know how to do that. From a quick look at the source, the place
I'd /expect/ to find that feature to be seems to be commented out.
I suspect that you'd be best off communicating directly with the Groovy
developers.
-- chris