tags:

views:

9

answers:

1

I'm using Janino to compile java files at runtime to use in a program. I'm using netbeans and I can only get it to compile at runtime when I put the directory in the src folder. If I try to compile it using relative paths It won't work.

I'm following the example at http://docs.codehaus.org/display/JANINO/Advanced#Advanced-compiler

Here's what works when i put the files to be compiled at runtime in a folder called scripts in the src directory:

        String engineClass = "DefaultEngine"; //name of engine class
        String guiClass = "DefaultGUI"; // name of gui class
        ClassLoader cl = new JavaSourceClassLoader(
                this.getClass().getClassLoader(),
                new File[]{new File("scripts")},
                (String) null,
                DebuggingInformation.NONE);
        AbstractEngine engine = (AbstractEngine) cl.loadClass(engineClass).newInstance();
        AbstractGUI gui = (AbstractGUI) cl.loadClass(guiClass).newInstance();

It doesn't work if I put the scripts folder in the same directory as the jar. I can only get it to work when I run the project from inside the IDE with the scripts folder in the src directory.

When I try running the project using the scripts folder in the same folder as the jar file it gives a ClassNotFoundException on the AbstractEngine engine = (AbstractEngine) cl.loadClass(engineClass).newInstance(); line

A: 

I figured it out. I had to put new File(System.getProperty("user.dir")+"/scripts") for the path

aexyl93