r/javahelp • u/prisonbird • Dec 20 '22
Unsolved Scripting language for Java
hello
i have to give my users ability to modify their data via simple code snippets. sometimes its simple math expressions ("price * 1.5" etc) sometimes they split strings, extract data from json etc. this gives my platform a lot of flexibility.
i want to use a fast scripting language in java. i tried graal.js with scriptenginemanager but it takes too long to boot up.
is there any faster alternatives or other approaches ? i am asking this because i just started using java and if there is a better solution in java ecosystem i dont want to miss it
thank everyone in advance for any help :)
16
Upvotes
2
u/Zyklonik kopi luwak civet Dec 20 '22
Unfortunately, OpenJDK removed its scripting engine support for good claiming that there weren't enough users to justify the maintenance effort.
What you want instead (depending on the seriousness/importance of your usecase) is a custom scripting language that compiles down to Java bytecode. https://javacc.github.io/javacc/ is what you want to be looking at. That way, you can embed your own language inside the same JVM (and indeed the same application) running your main application.
I personally would handcode a parser for a custom scripting language, but if you're not interested in that, or short on time, have a look at JavaCC linked above.