CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2010
    Posts
    17

    add method at runtime with JCompiler ![CODE]

    What is JCompiler?

    This class considerably helps you to compile at the run time. For using it, you should inherit from the JCompiler class, then use the “addFileToWindowsRuntime”, create a new class. Afterward you can create an object from the created class by using JShooter.


    ********************
    package mypackage;
    import org.j2sos.shine.jshooter.Application;
    import org.j2sos.shine.maplet.Maplet;
    public class Engine extends Maplet {
    public String name;
    public String body;
    public void learning() {
    try {
    new Memory().addMethod("public String " + name +
    "() throws Exception {" + body + "}");
    out.println("Learned.");
    } catch (Exception e) {
    out.println(e.getMessage());
    }
    }
    public void request() {
    try {
    Application app = new Application();
    app.setObject(new Logic());
    out.println(app.invokeMethod(name));
    } catch (Exception e) {
    out.println(e);
    }
    }
    }
    ********************************************************************************
    package mypackage;
    public class Logic {
    public String hello() throws Exception {
    return "hello user!";
    }
    ********************************************************************************
    package mypackage;
    import org.j2sos.shine.util.JCompiler;
    public class Memory extends JCompiler
    {
    public void addMethod(String body)throws Exception{
    new
    Memory().addCommandToClassBodyInWindowsRuntime("mypackage.Logic",body);
    }
    }
    **********************************Index.jsp***************************************
    <%@ page contentType="text/html;charset=windows-1252"%>
    <H1>Virtual Human</H1>
    <P>
    <a href="Learning.jsp">Learning.jsp</a>
    </P>
    <P>
    <a href="Request.jsp">Request.jsp</a>
    </P>
    **********************************Learning.jsp***************************************
    <%@ page contentType="text/html;charset=windows-1252"%>
    <H1>Virtual Human</H1>
    <form action="servlet/mypackage.Engine" method="get">
    <P>Method Name:
    <input type="text" name="name"/>
    </P>
    <P>Body:</P>
    <P>
    <textarea cols="40" rows="20" name="body"></textarea>
    </P>
    <P>
    <input type="submit" value="Submit"/>
    </P>
    </form>
    **********************************Request.jsp***************************************
    <%@ page contentType="text/html;charset=windows-1252"%>
    <H1>Virtual Human</H1>
    <form action="servlet/mypackage.Engine" method="get">
    <P>Method Name:
    <input type="text" name="name"/>
    </P>
    <P>
    <input type="submit" value="Submit"/>
    </P>
    </form>

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: add method at runtime with JCompiler ![CODE]

    What is your question or problem?

    As it states at the top of the thread list, this is a forum for Java programming questions and answers. Please try to grasp what that means.

    They know enough who know how to learn...
    J. Adams
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Feb 2008
    Posts
    966

    Re: add method at runtime with JCompiler ![CODE]

    Quote Originally Posted by dlorde View Post
    What is your question or problem?
    After looking at the example code, I think his question is: "why did I bother to write a useless example to try and advertise my useless product on a programming help forum." After looking as his other 10 posts where he claims that his product can solve every problem, and now apparently it is GREAT for servlets , it is obvious that we all should bow down and add this product to all of our production code. I for one submit to the awesome power of the Jcompiler.

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: add method at runtime with JCompiler ![CODE]

    why did I bother to write a useless example to try and advertise my useless product on a programming help forum.
    Given that most of people who frequent sites like this don't have a strong enough understanding of Java to be able to use such a product it can only be to alienate the few of us who might actually have been interested.

    As I said to the OP the other day, the thing to do is to write an article. That way at least the audience are interested in what you have to say.

    What is your question or problem?
    I'd like to know how many times we have to report someone before something is done about it?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: add method at runtime with JCompiler ![CODE]

    Yes, I'm all in favour of enthusiasts sharing their enthusiasms, but there is a time and place for everything. Pasting a generic "Use this toolkit, it's great!" response to every remotely related question topic is not the way to go.

    As Keang says, writing an article is the way to do it, and will hopefully keep him busy for a while...

    That language is an instrument of human reason, and not merely a medium for the expression of thought, is a truth generally admitted...
    G. Boole
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  6. #6
    Join Date
    Jul 2010
    Posts
    17

    Re: add method at runtime with JCompiler ![CODE]

    it was the question of most of developer .

    if you claim you are a developer so it must be your question too

    so I answer a question of all of the developer

  7. #7
    Join Date
    Feb 2008
    Posts
    966

    Re: add method at runtime with JCompiler ![CODE]

    Quote Originally Posted by OMID128 View Post
    it was the question of most of developer .
    Have some data to back up your claim?
    Quote Originally Posted by OMID128 View Post
    if you claim you are a developer so it must be your question too

    so I answer a question of all of the developer
    You don't know what questions I have. Your trivial little example answers what question that "all developers" have?

    Was the question: "man, if there were just some crazy framework that would allow me to write on-the-fly methods in my servlets because I have SOOO many people visiting my website that might want to run their own code on my sever..."

    Was it: "you know, with Spring MVC, Struts 2, JSF and Groovy there just aren't enough frameworks for servlets. does anybody know of one 'has it all' solution?"

  8. #8
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: add method at runtime with JCompiler ![CODE]

    Quote Originally Posted by OMID128 View Post
    if you claim you are a developer so it must be your question too
    No. Your current approach will only get you onto a bunch of ignore lists or a ban.

    On this forum please restrict yourself to answering explicit Java questions or asking Java questions for which you need an answer. I'm sure there are other forums that are happy to accept unsolicited software recommendations.

    You really don't want to get yourself a bad reputation or a ban on the Java forums - it's a small world.

    Experience is a poor teacher: it gives its tests before it teaches its lessons...
    Anon
    .
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured