compiling a class during runtime - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

compiling a class during runtime

markkelmarkkel Posts: 6Member
how do i compile a class (which has changed during runtime) during runtime?

Comments

  • ram302ram302 Posts: 3Member
    : how do i compile a class (which has changed during runtime) during runtime?

    : Just re-compile (if you're using and IDE, otherwise, just re-compile it with the javac command), but I don't think that your program currently running is gonna see any changes until you execute it after re-compiling it...I could be wrong, I sure hope not (I doubt it)

  • arb123arb123 Posts: 696Member
    : how do i compile a class (which has changed during runtime) during runtime?
    :

    You can recompile a class either by launching javac in a child process (can create spurious terminal windows under WIN32), or by calling the compiler class directly under the same VM. This second approach can be hit-and-miss because the compiler class varies between vendor implementations and Java versions (under Sun's Java 1.4.1 its [b]com.sun.tools.javac.Main[/b], but its been other things under other versions). Be careful if you're thinking about bundling the SDK with your app - the license for the full SDK is stricter than that of the JRE.

    You can reload the resultant class(es) using your own ClassLoader (see [b]ClassLoader.defineClass(String, byte[], int, int)[/b]). There are a whole raft of gotchas here, but if you search the 'net you'll come up with the info you need; suffice to say you're not the first person that ever wanted to do this.

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

  • markkelmarkkel Posts: 6Member
    : : how do i compile a class (which has changed during runtime) during runtime?
    :
    : : Just re-compile (if you're using and IDE, otherwise, just re-compile it with the javac command), but I don't think that your program currently running is gonna see any changes until you execute it after re-compiling it...I could be wrong, I sure hope not (I doubt it)
    :
    : My program involves getting the average running time of a users algorithm. the user writes the class containing the algorithm themselves. this is why i will need to compile this class during runtime...

Sign In or Register to comment.