Import java classes to a project automatically?

Asked

Viewed 355 times

3

I wonder if there is any way to automatically import java classes from a given local directory for my current project. For example: Let’s say that when I press a "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 that?

Specifying: I’m trying to build a system where programming beginners send their java class and the system evaluates that code. In principle this evaluation would only be 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 class imported into a project. This is why I am looking for a way to automatically import by having a specific folder on the server where the classes that students submit would be, if there is a way to automatically import them all into a project, I could perform the test case on all of them once they were submitted.

  • Import at runtime?? Doesn’t that make any sense to me.

  • 1

    These are different questions. It may seem pointless, but this is exactly what I need to build my system. This will give results to a class evaluation system that I’m building to help beginner students in programming. It’s a project of my college

  • It is not very clear what you want to import and how, it would be interesting to detail better what you said in the river comments in the body of the question, even so that it becomes more objective what you need.

  • 1

    I thought it was already clear. Well, I made a correction detailing more. Thanks for the suggestion

1 answer

3

Friend you can use the package com.sun.tools.javac JDK to compile a block of code at runtime, i.e., your java code compiling other java code 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: http://www.javaworld.com/article/2071777/design-patterns/add-dynamic-java-code-to-your-application.html

I hope it helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.