java.compiler module

javaCompiler ({ dest } )

Create a Java compiler. When dest is specified, the compile code are written to that place. dest can be ZipOutputStream, File, or String.

c = javaCompiler()
c = javaCompiler("classes")
zout = openZip("test.jar", "w")
c = javaCompiler(zout)
c.compile("Test.java")
zout.close()
c . addJavaFile (fileName, content )
(javaSourceFiles )

Register a pair of the specified file name and the content.

c.addJavaFile("Hello.java", readText("Hello.java"))
c.addJavaFile(walkDirectory("../src")[function (f) f.name.endsWith(".java")])
compile ( ) or
(javaSourceFiles ) or
(fileName , content )

Compile the Java source code. javaSourceFiles can be String, java.io.File, or an array/Collection/Generator of those types.

'compile(javaSourceFiles)' is equivalent to 'addJavafile(javaSourceFiles); compile()'.

'compile(fileName, content)' is equivalent to 'addJavafile(fileName, content); compile()'.

c.compile("Hello.java")
c.compile(walkDirectory("src")[function (f) f.name.endsWith(".java")])
c . setEncoding (String encoding )

Set a character encoding for subsequent compilation.

c.setEncoding("utf-8")
c . setSourcePath ( String sourcepaths )

Set the source path for subsequent compilation.

c.setSourcePath("src")
c . setClassPath (String classpaths )

Set the class path for subsequent compilation.

c.setClassPath("mylib.jar")
c.setClassPath(walkDirectory("lib")[function (f) f.name.endsWith(".jar")])
c . getClassLoader ( )

Get the class loader from which the compiled code are loaded.

c.getClassLoader().loadClass("MyClass")
getContext().setClassLoader(c.getClassLoader())
MyClass