I'm trying to write a program that allows users to create "plugins". Kind of like how the Linux bash shell can have commands added by putting a file in a directory, I'm trying to allow users to put their code in a directory, and have my program execute it.
I thought of a few ways to do this:
- Somehow manage to create my own scripting language and have users use that to write their plugins
- Find an existing scripting language that Java supports and use that for users to write their plugins
- Have the users write their plugins in Java, and compile them during my program's runtime.
Though all 3 options seem pretty bad, this is all I could think of, and option 3 seemed the best of the three. So, I did some research and saw that Java 1.6 onward supported runtime compilation of files. However, if the code the users write references some specific classes that I have in the base program, I'm not sure if the compiler will fail. Normally it would, but since my program is compiling it, I don't know if the compiler will allow them to use the classes in the base program.
I'd ideally like this to be as easy for the user as possible. My main question is whether the compiler will have an issue with referencing classes in my base program. I don't want to have to include a .jar with all my classes and have the users use it as a Library when they're developing. As I said, I want this to be easy for the user, and ideally, it should be as close to an Interpreted Language as possible. That's why I'd like to do this at runtime in my program, so that the users don't have to bother with compiling. They just need to put the .java file in a directory and run my program.
If someone knows whether the compiler will have an issue with the classes, or if they know a better way to go about this, that'd be great!
Thanks!