Search |
||
Using jrunscript to create a build scriptPosted by forax on September 13, 2006 at 3:00 AM PDT
The JDK6 provides a new command jrunscript that enables to execute script shell in Java environment. By default, jrunscript uses javascript as scripting language and provides some useful default functions like cp, cd, cat, etc. These global functions seem designed to ease the creation of build scripts, so i propose to show the basics of how to write such scripts. First, the script must create the directory that will contain classes : // project properties srcDir='src' classDir='classes' // target init mkdirs(classDir);
To run the script, just type
jrunscript yourScriptFileName.js in your shell
But this function is easy to write
using the package javax.tools
introduced by the JSR199 and available
in So compiling a source tree is done with the following lines in javascript :
function fileset(path,pattern) {
var set=new Array()
function callback(file) {
set.push(file)
}
find(path,pattern,callback)
return set
}
// target compile
echo('compile')
javac(fileset(srcDir,'.*\.java'),classDir)
you can notice that callback is some kind of
closure in javascript :)
function javac(fileset,destDir) {
compiler=javax.tools.ToolProvider.getSystemJavaCompiler()
fileManager=compiler.getStandardFileManager(null,null,null)
fileManager.setLocation(
javax.tools.StandardLocation.CLASS_OUTPUT,
java.util.Arrays.asList([new java.io.File(destDir)].valueOf()))
compilationUnit=fileManager.getJavaFileObjectsFromFiles(
java.util.Arrays.asList(fileset.valueOf()));
task=compiler.getTask(null,fileManager,
null,null,null,compilationUnit)
task.call()
fileManager.close()
}
We now have a basic script that compiles a java project,
ok, it doesn't have by example a way to declare dependency between
target like Ant but that's a good starting point.
»
Related Topics >>
Open JDK Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|