|
Comments
|
Today's Top SOA Links
Enterprise Scripting Languages Ease Development and Administration
The ideal solution for automating repeated tasks and creating extensible applications
By: Tugdual Grall
Nov. 16, 2005 05:00 PM
As developers or system administrators, we all have common tasks that must be replicated again and again. A few examples might be creating a new feature test, populating a test database with data, copying data from a file system to a database, or creating new user accounts.... You get the idea.
Java is more than a simple language. It contains many low-level features, including networking, input-output, XML manipulation, and threading, that have contributed to its success. It's also an enterprise-ready solution based on the services provided by the J2EE platform, including persistence, transaction management, security, Web services, and open connectivity using J2EE Connector Architecture. Java scripting languages extend the benefits of scripting development with the power of Java - with the goal of making Java development easier and more productive.
Java Scripting Language Offerings Table 1 lists some of the most popular languages built around Java.
Scripting in Action Listing 1 provides a small Java program that processes a list of strings and prints those that are shorter than six characters. Here's the same program written as a Groovy script:
list = ["BeanShell","Groovy","Jacl","JRuby","JudoScript","Jython","Rhino"] As you can see, using Groovy dramatically reduces the number of lines of code that you have to write. It's also easier to read. In addition to a very concise syntax, most scripting languages provide high-level constructs for dealing with most of the components that current systems use. For example, many provide APIs for manipulating XML documents, simplifying database operations, or creating user interfaces. Some languages such as BeanShell, Groovy, and JudoScript also have native integration with Apache Ant to facilitate build and test tasks, as discussed in the next section.
Scripting Languages and Apache Ant The following example shows how BeanShell instructions can be embedded in a build.xml file: You can also replicate Ant scripting using Groovy. In this case, you wouldn't use XML to manipulate the different tasks; instead, you'd use a real scripting language, which would allow better constructs such as loops and logical branching. You can even mix Ant and Groovy operations in a single script file.
Where Should You Use Scripting Languages? Although some developers often question its use, you can use scripts to build complex applications - or at least use them inside complex applications or systems. Outside of the Java world, developers have used languages such as PHP, Perl, Python, and Tcl to create multiple Web sites or as part of complex integration projects. The story is much the same with regard to Java scripting languages. While you might not be able to completely build a complex application using one of the scripting languages I've mentioned, these technologies can help you create more agile solutions. As a developer, you may often have to add new business logic to your application due to constantly changing requirements. However, you may also need your application to be extensible so that advanced users or third-party developers can plug in their own modules. Administrators and developers can use scripts to connect to a Java application (such as J2SE or J2EE) using JMX so they can configure and deploy it. This is another example where scripts leverage a low-level Java API to easily perform complex tasks. For such uses, scripting languages are ideal. Already, some Web applications, such as Portal or Wiki, let developers add new features by publishing their own scripts to the product. Desktop applications based on Swing, SWT, or even native languages also offer extensibility based on scripts. Another example is the service-oriented architecture world, where the goal is to interconnect various services. Here, using scripting technologies to provide the plumbing in a loosely coupled manner is especially practical, since scripts are easy to change and completely dynamic.
Wrapping It Up Another sign of the importance of scripting in current development projects is that scripting technologies will be directly integrated into Java; Java 6 (code name Mustang) will contain a JavaScript interpreter based on Rhino. Also, the JSR 223, Scripting for the Java Platform, is a JCP specification that defines a low-level API to expose a scripting language engine to the Java platform. The current reference implementation integrates PHP, JavaScript, and Groovy. Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||