Writting a class file

G

gal

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
 
G

gal

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
 
T

Thomas Hawtin

gal said:
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
 
C

Chris Uppal

gal said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top