JOnFly


About JOnFly

 

With JOnFly you can easily create and run Java source code from within Java programs. JOnFly compiles and runs the code. You have access to standard and other functions.

Example: Creating Source Code

 

Documentation:

JOnFly is made out of only two classes, JOnFlySource and JOnFlyExecutor.

You can find the full java documentation here: Link

 

License:

Attribution 3.0

 

 

 


Example: Hello World

 

package org.jonfly;

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.logging.Level;

import java.util.logging.Logger;

 

/**

 * A demo class.

 * @author David Traum

 */

public class JOnFlyDemo {

    

    public static void main(String[] args){

        JOnFlySource source = new JOnFlySource("MyClass", new String[]{

            "public class MyClass{",

            "private String message = \"Hello World\";",

            "public MyClass(){",

            "System.out.println(message);",

            "}",

            "public static void main(String[] args){",

            "new MyClass();",

            "}",

            "}"

        });

        JOnFlyExecutor exec = new JOnFlyExecutor();

        

        try {

            Process p = exec.executeSource(source);

            InputStream in = p.getInputStream();

            InputStreamReader isr = new InputStreamReader(in);

            BufferedReader br = new BufferedReader(isr);

            System.out.println(br.readLine());

            br.close();

            isr.close();

            in.close();

        } catch (IOException ex) {

            Logger.getLogger(JOnFlyDemo.class.getName()).log(Level.SEVERE, null, ex);

        } catch (InterruptedException ex) {

            Logger.getLogger(JOnFlyDemo.class.getName()).log(Level.SEVERE, null, ex);

        }

        

        

    }

}

 

 

Example: Running Code from a JTextArea (Swing GUI)

 

JOnFlySource source = new JOnFlySource("MyClass", textarea.getText().split("\n"));

JOnFlyExecutor executor = new JOnFlyExecutor();

executor.exec(source);