Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

compiling the file at run time

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Is there any way that i can compile and then load the class at runtime.

If so please send me the source code and help me out. Its very urgent for me.

Thanks,
Suresh Bab
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can compile a class at run-time by just running "javac" via Runtime.exec(). I believe there is also a direct interface to the Java compiler. That would be more efficient and possibly more flexible, but I have not used it so I cannot give details; search Sun's documentation.

If your compilation generates a class file in a directory that is already on the class path, then you can easily load the class (e.g. with Class.forName()). Alternatively, with a custom ClassLoader of your own, you can load it from wherever it is.

Don't put "it's urgent" in your posts. This is likely to reduce, rather than increase, the number and quality of replies. EaseUp.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's possible to drive the Java compiler from within Java code, either through a Sun-internal API (for JDKs before Java 6), or in Java 6 through the new official API. Articles that describe both methods are linked in the JavaIntermediateFaq.
[ June 29, 2007: Message edited by: Ulf Dittmer ]
 
I child proofed my house but they still get in. Distract them with this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic