I am looking for a way to compile Java Source-Files at runtime and save them all in an executable jar; almost like an IDE would do.
I know that there is the javax.tools package which provides a JavaCompiler interface and you can use ToolProvider.getSystemJavaCompiler() to get an instance of a compiler. However, this method has one important problem: it only works on machines that have the JDK installed. Not when only the JRE is installed.
I guess at this point that I need some kind of third party library that offers an implementation of a JavaCompiler. Unfortunately, this is really complicated to search for on the internet since all top listings when searching "compile java at runtime jre" do not really provide a solution to the problem.
But there must be a solution, right?
Now you might be curious why I would need this and I am going to explain, just in case:
I am writing a (somewhat) complex simulation software right now which is supposed to be used by people who have absolutely no knowledge of programming. At the same time, this software should provide the user with a certain amount of flexibility and control over the flow of the simulation.
My previous take on this problem was to build a complex system to interprete user settings from a GUI. I would basically read the GUI input, output it to some kind of own scripting syntax which I just quickly made up and have that interpreted at runtime. Then I realized, that is a silly concept and I threw it out before I got far into the developement.
The much better solution I came up with is taking the input from the GUI, create java source code from it and compile it at run-time. Seems much cleaner and nicer to me; will also probably have a better performance, but thats not really an issue anyways.
Yes I know, I could also use some kind of existing scripting syntax like Ruby, Python, or whatever. But I already know java fairly well, and it is a java application, so why not stick to what I already know.
So yeah, thank you very very much if you could point me in the right direction.