Scripting in Java [closed]

Me and some friends are writing a MORPG in Java, and we would like to use a scripting language to, eg. to create quests.

We have non experience with scripting in Java. We have used Python, but we are very inexperienced with it. One of us also have used Javascript.

What scripting language should we use? What scripting language should we not use?

Asked by: Brad318 | Posted: 28-01-2022

Answer 1

I'm responsible for a fairly large hybrid Java/Jython system. We use java for core API development, then wire Java objects together using Jython. This is in a scientific computing environment where we need to be able to put together ad-hoc data analysis scripts quickly.

If I were starting this system from scratch today, I would not choose Jython as the scripting language. I like Python fine, but I frequently encounter awkward mismatches between the Python type system and the Java type system. For example, if you just want a hashtable, should you use a Python dictionary or a Java HashMap? The decision might be different depending on whether you are just using the data structure locally in Python code or passing it across the Java boundary. Jython does a certain amount of type coercion for you, but it's not perfect. It's annoying to even have to think about issues like this when the purpose of using a scripting language in the first place is to enhance your productivity.

I assume JavaScript or JRuby would have similar issues. Today I would choose a scripting language that is specifically targeted to the JVM and leverages the Java type system. The obvious candidates are Groovy and Beanshell; Groovy seems to have been picking up momentum lately so I'd look most closely at it.

Answered by: Caroline998 | Posted: 01-03-2022

Answer 2

I agree with Viktor's Jython suggestion. Other than that and JavaScript (which you've mentioned, and is built into Java 6+ via the javax.script package), Groovy and JRuby are also worth looking at too.

By the way, you should look at Wyvern, also an MMORPG written in Java and using Jython for scripting. Steve Yegge, its author, has much to say about it from time to time. :-)

Answered by: Arnold105 | Posted: 01-03-2022

Answer 3

Java supports a variety of (scripting) languages, some are listed in Wikipedia here and here. You probably should choose language with powerful DSL and metaprogramming capabilities, such as Clojure.

But if you need something simpler, JavaScript might be a viable alternative.

Answered by: Walter573 | Posted: 01-03-2022

Answer 4

How about Jython?

Answered by: Joyce431 | Posted: 01-03-2022

Answer 5

what about creating your own specialized scripting language? If your app is written with java, you can use ANTLR ( to create your language parsing code.

The reason I say this is because a general purpose scripting language may provide too much power (because the script it to be used for quests only i assume).

But if making your own language is too hard then any of the above suggestions works - you just have to figure out how to bind the game's runtime into the script. I also suggest Lua ( as another choice that lots of games use.

Answered by: Aida642 | Posted: 01-03-2022

Answer 6

Short version

Don’t use a scripting language! Instead focus on configurability (which is something that a non-programmer can do well).

Longer version

One oft-used argument in favour of having a scripting language is that it allows for lesser programmers to more trivial tasks. Don't belive this, it will not save you any time, since trivial tasks are already accomplished by real programmers in no time. Aim for configurability instead of scripting, and you will have a much lower risk of bleeding over complex algorithms and concepts into the incapable hands of game designers. :)

Lack of hotswapping (edit-and-continue) would have been a reason to implement a scripting language in an MMOG (you don’t want to reload the whole game for a minor code change), but using Java, with built-in hotswap, you really have no reason for adding a scripting language on top.

I have spent years pondering these questions; in the day I implemented a complete scripting language, IDE, VM, debugger, etc for an MMOG myself. Since, I have grown wiser.

If you still choose to go down the infinitely crappy path of no return, keep the following in mind.

  • Pick a mature language which has been around for a while.
  • Auto testing, debugging and editing will suck bigtime until you make your own tools/plugins/start hacking around in the VM.

To date, I have never seen a DSL that improved the situation (getting a more maintainable product). Myself, I integrated Python into my indie game engine, but eventually came to my senses and ripped it out. "Stackless Python" is just a way of saying "unmaintainable but fast". Please, anyone correct me if I'm wrong?

Answered by: Maria738 | Posted: 01-03-2022

Answer 7

See Java: Scripting language (macro) to embed into a Java desktop application

Answered by: Catherine510 | Posted: 01-03-2022

Answer 8

You have quite a few options:

Possibly even BeanShell (

I'm a fan of Python myself so I'd recommend Jython, but they're probably all reasonable options.

Answered by: Maya574 | Posted: 01-03-2022

Answer 9

I would have to recommend Javascript for this purpose. Mozilla Rhino is an excellent implementation that would fit your needs perfectly.

I recommend Javascript over Jython or JRuby because of familiarity. Trivial Javascript follows a very familiar syntax that anybody can use. However if someone wants to do something more intense, Javascript is a very powerful functional programming language.

I regularly use Groovy and Ruby professionally and believe that their purpose is best for writing parts of applications with particularly complex logic where Java is cumbersome to write. Javascript is a much better choice as an embedded, general scripting language to use in a game. I haven't used Python, but it's syntactically similar to Ruby and I would believe it's purpose would also be similar.

Answered by: Rafael935 | Posted: 01-03-2022

Answer 10

LuaJ seems to be a nice way to embed Lua into Java:

Answered by: Arnold268 | Posted: 01-03-2022

Answer 11

I am a big fan of Python/Jython due to the clean syntax - which may suit you if you have some python experience.

Otherwise Groovy which is based on Java syntax and may be an easier learning curve if most of your developers are Java guys. It also has the advantage of closer ties with the Java language and libraries.

Beanshell is good if you have simple scripting in mind - it doesn't support classes. However I don't think it has had any support over the last few years (the JSR seemed to kill it off...) so is perhaps a bad choice if support is important to you.

Answered by: Elise138 | Posted: 01-03-2022

Similar questions

scripting - JRuby and Java objects

Please tell me if it is possible to do the following: create an instance of a specific class in Java pass it to JRuby to do something with it continue using the "modified" version in Java May you provide a small working example? EDIT: It turns out that embedding was the simplest way to achieve this. More information is available on

Security with Java Scripting (JRuby, Jython, Groovy, BeanShell, etc)

I'm looking to run some un-verified scripts (written in a yet-to-be-determined language, but needs to be Java-based, so JRuby, Groovy, Jython, BeanShell, etc are all candidates). I want these scripts to be able to do some things and restricted from doing other things. Normally, I'd just go use Java's SecurityManager and be done with it. That's pretty simple and lets me restrict file and network access, the ability ...

java - Bean Scripting Framework

I'd like to use the Bean Scripting Framework to make some of my Java classes be available to users at my company who wish to write scripts + who may be familiar with Javascript or Python (via Jython) or Ruby (via JRuby). I can't really find much tutorial documentation on how to get BSF working... what I would like to do is make a Java ...

scripting - JSR223: Calling Java "varargs" methods from script

I have a method that looks like this on Java: public void myMethod(Object... parms); But I can't call this method as expected from the scripts. If, in ruby, I do: $myObject.myMethod(42); It gives me org.jruby.exceptions.RaiseException: could not coerce Fixnum to class [Ljava.lang.Object If I try the following in Javascript:...

api - Java + Scripting languages (JSR 223)

I'm designing a Framework which I want to attach to the scripting language API to make it more versatile and easier to use (for some things I really prefer the scripting way myself ;). With languages like JRuby, Jython or Rhino (JavaScript) there are interpreters for many popular scripting languages available and as far as I read, all of them implement the

Scripting (with PHP) in Java?

I'm trying to write a simple Java game. I have a NPC class, with a function Dialog which returns what the npc would say, which would depend on various conditions. I'm thinking that it would probably make sense to offload the logic of deciding what each npc would say to a scripting language, so that it could be changed updated easily. That way, I can create each NPC instance using something like npc Mayor = ...

javascript - is it possible to build a debugger around the java scripting engine?

Closed. This question needs to be more focused. It ...

java - Measure code coverage for remote scripting tests

Closed. This question does not meet Stack Overflow guid...

java - How to justify using a scripting language as part of a project

I have a specific project in which I want to use either a scripting language + C, or as an alternative a 100% Java solution. The program adapts a legacy system for use with other moderns systems. Basically, I have few choices as to what language I can use. I have C/C++, Java 1.4, and I have also compiled the Lua for this environment. The program does 'screen scraping' and has to deal with alot of s...

Is there a Java Scripting Language that Can Work Without Caching? Jython? Groovy? etc?

We have an existing java-based heavyweight project that needed an interactive script interpreter. After a fair amount of research we eventually ended up with Jython, one of the reasons being that the customer's group already has a large amount of python expertise, and it's an easier sell to give them an api in a language close to one they already know. Alright, well at first this was fine, but there turn...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)