Calling Scripts in MavenDo you use Maven, but don't like programming in Jelly? The idea is to be able to write short scripts in a “real” programming language. Personally, I prefer a Java-like programming language like BeanShell or Groovy, but Jython has many fans. I have been trying to get BeanShell and/or Groovy working in Maven 1.0.2 with limited sucess. There are a variety of possible tags that can be used for scripting, some of which work and some that don't. There are a handful of Jelly tags for embedding scripting languages, here is a (partial?) list:
This is the only approach that I've been able to get working in Maven 1.0.2. There is a bsf:script tag, but I could not get it to work. I know of at least one language-specific Ant task for scripting, and am sure there are others that can be added to the list. The jsr-02 release of Groovy (not yet available as of this writing) will include the Groovy Ant task that can been used within Maven. There is a Script task in Ant, but it doesn't seem to work from within Maven 1.0.2. This is an interesting possibility that I have not had time to investigate. There is at least one webpage that shows how to do it with BeanShell.
These sample files document the approach used to get the best results so far with Maven 1.0.2. Example 1. maven.xml <?xml version="1.0"?> <project xmlns:j="jelly:core" xmlns:util="jelly:util" xmlns:ant="jelly:ant" xmlns:bsh="jelly:beanshell" xmlns:jython="jelly:jython" default="all"> <goal name="test-bsh"> <bsh:script> System.out.println("Hello from BeanShell, pom.getName() = " + pom.getName()); </bsh:script> </goal> <goal name="test-jython"> <jython:script> print "This is a jython script" print "My Maven POM's name is", pom.getName() print "If the POM has a name, then the context passing is working" </jython:script> </goal> <goal name="all" prereqs="test-bsh, test-jython" /> </project> Example 2. project.xml <?xml version="1.0" encoding="ISO-8859-1"?> <project> <!-- Skipped --> <dependencies> <dependency> <groupId>bsf</groupId> <artifactId>bsf</artifactId> <version>2.3.0</version> <type>jar</type> <url>http://bsf.apache.org/</url> </dependency> <!-- Stuff for Calling Beanshell --> <dependency> <groupId>bsh</groupId> <artifactId>bsh</artifactId> <version>1.2-b3</version> <type>jar</type> <url>http://www.beanshell.org/</url> </dependency> <dependency> <groupId>commons-jelly</groupId> <artifactId>commons-jelly-tags-beanshell</artifactId> <version>1.0</version> <type>jar</type> </dependency> <!-- Stuff for Calling Jythhon --> <dependency> <groupId>jython</groupId> <artifactId>jython</artifactId> <version>2.1</version> <type>jar</type> <url>http://www.jython.org/</url> </dependency> <dependency> <groupId>commons-jelly</groupId> <artifactId>commons-jelly-tags-bsf</artifactId> <version>1.0</version> <type>jar</type> </dependency> </dependencies> <!-- Skipped --> </project> |
|
|