• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

can i compile java from java code?

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all
can i compile java source from java code?
the reason i asking is :
i have some test files that representing classes and methods and i need to transform them into java code ( i know to do the lexing ) and then this code compile and store some how the class's in memory . can it be done in java 1.5 ?
not 1.6 .
thanks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, this can be done. The JavaIntermediateFaq points to two different ways, in a paragraph about expression evaluation, towards the end of the page.
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
well this is cool way to comiple java , but i meant more like
compiling the java source and manege all the classes/object created
in memory and not like "real *.class" files.
thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to do everything in memory, you can use the Javassist library, which is also linked on that page.
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thanks for the replay , as i see it still reads class files
that compiled in some form . i need to do every thing in memory .
to transform file (idl ) to java source and compile it then store the
classes in memory .
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, Javassist does not read existing class files. It can do that, but it's not necessary. I've used it to create classes in memory from scratch, with no reference to any existing class.

But now that you mention IDL files, it seems that you are actually trying to do something very different. In order for us to help you, we'd need to know more about what exactly that is.
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i need to do is :
compile idls -> use the java source generated -> compile to classes
and all this in memory .
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm going to slide this over to the intermediate forum...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to do this all in memory. Have a look at the API documentation of the package javax.tools in JDK 6; especially the interface JavaCompiler.

The compiler works with JavaFileObject objects. A JavaFileObject represents a Java source or class file. But it doesn't really need to be a file on disk; you can create your own subclass of JavaFileObject that keeps the source and compiled classes completely in memory, instead of writing them to disk.

The newest version of Glassfish (Sun's open source Java EE server) is doing something like this: from JSP's it generates source code for a servlet and compiles it, all in memory. Because it's done all in memory, it works very quickly.
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah i know , but i need it for java 1.5
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suns idlj compiler is written in Java, but its help seems to imply that it expects a file as input. But maybe you're using a different IDL-to-Java compiler?

Why does it all have to happen in memory in the first place?
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thanks for the reply
i need it in memory coz , this is a client application every time that the
server stub changes i could give the client new idl . now it is abig pain
to compile and manage 40 idls . for the client .
Thanks
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any news with this problem ?
im using idlj.
mybe there is different approch to this problem ?
reply
    Bookmark Topic Watch Topic
  • New Topic