Sign in to follow this  

Extend Java app with scripting and configuration

This topic is 2055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a tool written in Perl, about 2600 lines of code.
The tool is used to parse XML files and genrate C++ source based on certain rules.
I'm going to rewrite the tool in Java because I'm expecting the tool will become quite complicated in the future and Perl code maybe hard to maintain (no need to debate on this please).

The reason I used Perl is then I can use simple Perl script as configuration and scripting.
The tool needs a lot of configuration and also that it needs to allow the user to handle certain events in script.

My question is, I want to hear your advice on how to do scripting, or which script language to use in Java?

My requrements:[list=1]
[*]Lua, Perl, and Javascript are most prefered. Python is OK. Any other simple scripts that only require 10 minutes to learn are also OK but not prefered. The tool only needs one scripting language, not all the scripts mentioned above.
[*]Java only. No need native executable. This is negotiatable but I highly prefer this point.
[*]The script can handle and modify Java objects.
[*]Easy to integrate to my tool. I don't want to spend one day on compiling the script binding library.
[*]Native regular expression support in the script. Not a must but a hope.
[/list]

I googled and found several candidates, but I'm not sure which one is best.
I think a lot of folks here had extended Java with scripting in your tools, so I would like to hear from you.

Thanks

Just to help you understand, below is a Perl script as the config. The user just passes its file name then the tool will load it and run it as Perl code.

[CODE]
$config = {
title => 'blah blah',

autoRegister => 1,

outputCallback => \&processCallback,
};

sub processCallback
{
# Perl code here to handle the callback
}
[/CODE] Edited by wqking

Share this post


Link to post
Share on other sites
[quote]My question is, I want to hear your advice on how to do scripting, or which script language to use in Java?[/quote]
Unlike C/C++, Java - and .Net - is less of a language and more of a platform via the JVM. Thus, there are an extremely large number of JVM languages that can interpolate with Java sans any explicit binding.

[quote]Lua, Perl, and Javascript are most prefered. Python is OK. Any other simple scripts that only require 10 minutes to learn are also OK but not prefered. The tool only needs one scripting language, not all the scripts mentioned above.[/quote]
As far as I am aware, both Lua (LuaJ, et. al) and Perl (JPL) have bindings but aren't overly popular (I've never used either myself nor have I seen any questions regarding them). Rhino is the Javascript implementation in Java (and it is quite fast) and Jython is the Python version.

[quote]The script can handle and modify Java objects.[/quote]
Most of them do it natively (e.g. there are no explicit bindings) courtesy of the JVM. As a side effect, they also have access to all of Java's libraries.

[quote]Java only. No need native executable. This is negotiatable but I highly prefer this point.[/quote]
Most of them are fully implemented in Java or have the natives buried in an archive and you never need to mess with it.

[quote]Easy to integrate to my tool. I don't want to spend one day on compiling the script binding library.[/quote]
That's more of a design problem as "easy to integrate" depends on your tool. That said, working with scripting languages in .Net or Java is nothing like dealing with the same in C/C++.

[quote]Native regular expression support in the script. Not a must but a hope[/quote]
A lot of them do, and the ones that don't can simply piggy-back Java's implementation if need be.

[quote]I googled and found several candidates, but I'm not sure which one is best.[/quote]
"Best" is relative to your project's needs. If you're looking for simple, then Rhino is an excellent choice (just make sure you download Mozilla's SDK and avoid the butchered abomination included in the Java distribution) as it provides a nice balance of speed and flexibility. If you want something more substantial then JRuby or any of the other myriad of OO oriented languages might be appropriate. For raw speed Scala or Groovy++ ([i]not[/i] dynamic Groovy) is as fast as they come.

The nice thing about platforms like .Net and Java is that your scripting language choice is more about personal preference and less about which language's bindings will include the least amount of suffering in order to get operational. Download the archives, plop them on your classpath, and be productive.

Share this post


Link to post
Share on other sites
Update, I just tested Rhino for a while. It works perfect for me and meets all my requirement.
Even better, I don't need to compile it. There is a JAR with only 1M file size there.
Very good. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites

This topic is 2055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this