开发者

What are use cases for Groovy Scripting besides Java / Groovy classes? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

Improve this question

I am playing around with Java, Groovy and Scala at the moment. Groovy enables to write scripts besides classes, which is often stated as a big advantage of Groovy because you can write applications and scripting with the same language.

Can you please tell me some use cases where it does make sense to use Groovy scripts?

For me, a script is something like unix shell scripts which copy files or stuff like this. Besides, I use JACL and Jython scripts for WebSphere Application Server deployments.

My question: When should I use Groovy scripts? Should I use them for copying files instead of unix s开发者_JAVA百科hell scripts (thus, I have classes and scripts in the same language for easier maintenance) or when else should I use Groovy scripts?

Thanks.

Best regards, Kai


Groovy scripts are interpreted within the JVM. This gives us the ability to dynamically modify the behavior of a program at runtime. Runtime configurability is an important feature in many types of applications. For example, in web applications and business process driven applications, conditional flows or branching can often be changed at runtime. Using Groovy, all you need is to change the script and make it available in some standard location from which the application can pick it up and execute.

There are a few other scripting languages available out there, but Groovy has the added advantage that it can interact very well with the available java objects and libraries making it a good fit within Java applications.


I have found Groovy scripts are great for tasks that change often and benefit from the extensive availability of Java libraries. Their use allows me to respond quickly to dynamic business processes such as data integration with JDBC, file transfers with Apache Commons, and encryption with BouncyCastle.


I love groovy scripts because they are the easiest way to programmatically interact with a Maven build. Just use the Gmaven plugin, and you can write Groovy Scripts (inline or in external files) that can modify your project structure at runtime (whereas you'd have to write a custom plugin in a separate project to do that in Java).


Groovy scripts are also great for DSLs ( http://en.wikipedia.org/wiki/Domain-specific_language ).

A good example of this would be the build tool Gradle ( http://www.gradle.org/ ).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜