This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes can i compile java from java code?  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can i compile java from java code?  " Watch "can i compile java from java code?  " New topic
Author

can i compile java from java code?

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
Yes, this can be done. The JavaIntermediateFaq points to two different ways, in a paragraph about expression evaluation, towards the end of the page.


Ping & DNS - my free Android networking tools app
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
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
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
If you want to do everything in memory, you can use the Javassist library, which is also linked on that page.
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
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
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
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.
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
what i need to do is :
compile idls -> use the java source generated -> compile to classes
and all this in memory .
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8801
    
    5
i'm going to slide this over to the intermediate forum...


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
Consider Paul's rocket mass heater.
 
subject: can i compile java from java code?
 
Similar Threads
can I invoke java commands from a class?
reading
SCJP2 Question - Compiler Error Vs. Run-time Error
can i compile java from java code?
Dumb question here