r/javahelp • • 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

23 comments sorted by

View all comments

4

u/Battlepine Dec 20 '22

Groovy works well for my team.

1

u/prisonbird Dec 20 '22

how do you run groovy ?

1

u/Battlepine Dec 20 '22

Their documentation is really good.

https://groovy-lang.org/documentation.html

Groovy is extensible w/ Java enough that I've literally copied code from unit tests in Java, repurposed it a bit, and ran it within Groovy. It makes it super easy to test and get performance insights from pain points in code.

0

u/prisonbird Dec 20 '22

i know groovy but what i meant is : i have a web ui, i am getting some piece of code from the users. and i have to run this code on my backend for a lot of records in my database. what should be the correct approach to do this ?
i am not experienced in java ecosystem and i feel like first thing i saw in the documentation might not be the correct approach since my use case is weird

1

u/pragmos Extreme Brewer Dec 20 '22

1

u/Zyklonik kopi luwak civet Dec 21 '22

The script engine has been deprecated for OpenJDK, however. It's only available via GraalVM, I believe.

2

u/pragmos Extreme Brewer Dec 21 '22

The module is still there for Java 17 though. Maybe you meant the JavaScript engine implementation (Nashorn, was it?) was removed from the JDK.

1

u/Zyklonik kopi luwak civet Dec 21 '22

Ah yes, my bad. Yes, it was the Nashorn script engine which was deprecated via JEP 335.