开发者

Best scripting language to wrap a Java process in? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I have a Java server process that I normally run in either Windows batch file consoles or in Linux Bash script consoles. I manage these scripts independently of each other and I wish I had something that was cross platform, more powerful, and easier.

Besides running the java process itself, the scripts need to create files, configure files, read/write .xml config data, prepare databases, etc.

So, which scripting language would be the best for this that would allow the script to go cross platform?

Also, if开发者_JS百科 you have heard of someone doing something similar to this, I would love a link to see the example.


Edit to actually phrase this as an answer:

Just use Java.

Is there a reason that you can't write that stuff in Java as well, and just have some different functions for the few things that aren't cross-platform?

Second edit is a counter-example. My company has a dev team that writes cross-platform Java code, but the scripts for running/upgrading it are written in .SH and .BAT, depending on if it will be Windows or Unix. So they write it twice, in the lowest-common-denominator for the two target platforms.


I think Groovy would be a great choice. It's syntax is very similar to Java, but it is much more concise (than Java), particularly for the kind of things you need to do in scripts. For example, here's a Groovy script that reads the content of a file:

String content = new File("/path/to/file.txt").text

That's it! There's no need to put it inside a class or even compile it. Just put the text above in a file named Script.groovy and invoke it from the command line using groovy Script.groovy.

Also, because Groovy runs on the JVM there should be no cross-platform issues, and you'll already have the necessary runtime installed on all the machines you need to run your scripts on.

Groovy comes with a console that you can use to quickly test out your scripts.


You also might want to consider putting the "script" stuff in a Jruby script and then having it invoke your Java apps and libraries when necessary. That would work fairly well. The downside is that you would need to maintain a Jruby runtime on all of your servers.


Correct me if I a mistaken, but isn't the point of things like Ant to have a build process in Java itself? I feel that if you had a standardized Java build process that did these things for you, your batch file, bash script, or the necessary derivatives could be much, much simpler. Then again, IANAJDNEC (I am not a Java developer, not even close).


We did similar thing by ensuring all machines have cygwin. The scripts becomes more portable. Now trying to replace the shell scripts with perl scripts.

We also moved most of the functionality into java code.

If this about managing an environment, I recommend jenkins farm. It has many builtin task, you may reduce your scripting effort. One of the main feature is to deploy jdk on all machines transparently and then start java tasks there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜