Import java classes to a project automatically?

3

I wonder if there is any way to automatically import java classes from a given local directory to my current project. For example: Let's say that when I press an "Import" button in my application, all java classes that are in "c: / my folder / my_classes" will be imported into my project. Is there any way to do this?

Specifying: I'm trying to build a system where beginners of programming send their java class and the system evaluates this code. At first this evaluation would be only through simple test cases in the classes that are submitted in the system. But even so, to run a test case, you need to have the imported class for a project. This is why I'm looking for a way to automatically import Having a specific folder on the server where the classes that students are going to be would be if there is a way to import all of them into a project automatically, I could do the test case in all of them as soon as they were submitted.

    
asked by anonymous 10.03.2016 / 01:09

1 answer

3

Friend you can use the package com.sun.tools.javac of the JDK to compile a block of code at runtime, ie your code in java compiling other code in java during execution.

An example:

int errorCode = com.sun.tools.javac.Main.compile(new String[] {
        "-classpath", "bin",
        "-d", "/temp/dynacode_classes",
        "dynacode/sample/PostmanImpl.java" });

But details of how this works, you can follow this link: link

I hope you have helped.

    
10.03.2016 / 03:07