'Is there a way to run a Java Program when you don't know its name?

I'm making a game engine using LWJGL. The developer using it has to be able to use scripts. I decided to just make them use Java because writing an API in another language wasn't something I'm going to have the time nor experience to do. Anyways, I would have used x.main(); to run it, but The developer tells what the script is named, and that is stored in a variable. I just thought I could run a command to do that, using a method like exec() in python or eval() in JavaScript. I couldn't find a library that has this execution functionality and if there was, it just wasn't straightforward enough for me to wrap my mind around it. if you don't know any libraries that have this functionality, but have a recommendation of something I should try, I'd love to hear it.

To summarize this paragraph, I need a Java Library that can use a method like JavaScript's eval() or python's exec()

Any help would be greatly appreciated.



Solution 1:[1]

One (quite popular) tool that can help you run Java sources as scripts is JBang. Java programs have to be compiled (to Java class files) to be able to run by a JVM. So, basically, JBang hides this compilation step and invokes the JVM with our compiled class.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michail Alexakis