Visitar URL original
Run compiled class in separate Java process · Issue #6 · trung/InMemoryJavaCompiler · GitHub
The Wayback Machine - https://web.archive.org/web/20210124152025/https://github.com/trung/InMemoryJavaCompiler/issues/6
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run compiled class in separate Java process #6

Open
lfuelling opened this issue Feb 24, 2016 · 1 comment
Open

Run compiled class in separate Java process #6

lfuelling opened this issue Feb 24, 2016 · 1 comment

Comments

@lfuelling
Copy link

@lfuelling lfuelling commented Feb 24, 2016

Hi @trung,

I'm using your library to compile code that's coming from a web interface. After compilation I'm running the compiled class to evaluate the output.

If a user inputs something like System.exit(0);, the server will crash. I tried to prevent this by running the compiled class in a separate process like this:

public static int exec(Class clazz) throws IOException,
            InterruptedException {
        String javaHome = System.getProperty("java.home");
        String javaBin = javaHome +
                File.separator + "bin" +
                File.separator + "java";
        String classpath = System.getProperty("java.class.path");
        String className = clazz.getCanonicalName();

        ProcessBuilder builder = new ProcessBuilder(
                javaBin, "-cp", classpath, className);

        Process process = builder.start();
        process.waitFor();
        return process.exitValue();
    }

The problem with this is that I'm getting a "Class not found" error everytime I try to run the compiled class like this.

Is it possible to run the compiled class in a separate process using another way?

@trung
Copy link
Owner

@trung trung commented Sep 24, 2017

I think it's due to the your application class loader can't find the class which was dynamically compiled.

I need to try this myself but my thinking is that there should be additional step in your application to load the dynamic compiled class in the application class loader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants