Last active
June 6, 2016 12:55
-
-
Save roryl/3580c74e7749ba8bd7e7d7d07278cc66 to your computer and use it in GitHub Desktop.
Lucee Java Compilation Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*.class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
this.javaSettings = {LoadPaths = ["./"], loadCFMLClassPath = true, reloadOnChange= true, watchInterval = 2, watchExtensions = "jar,class,xml"} | |
function onRequestStart(){ | |
compileClasses(); | |
} | |
/** | |
* compiles all .java files in /WEB-INF/lucee/classes via the ECJ BatchCompiler | |
* lucee code added to classpath via the jars in System classpath and the latest rc patch | |
*/ | |
function CompileClasses() { | |
var java = { | |
System : createObject( 'java', 'java.lang.System' ) | |
, PrintWriter : createObject( 'java', 'java.io.PrintWriter' ) | |
, StringWriter : createObject( 'java', 'java.io.StringWriter' ) | |
, BatchCompiler : createObject( 'java', 'org.eclipse.jdt.core.compiler.batch.BatchCompiler', 'ecj-4.2.2.jar' ) | |
}; | |
var src = expandPath( '' ); | |
var rc = arrayLast( directoryList( expandPath( '{lucee-server}/../patches' ) ) ); | |
var cp = java.System.getProperty( "java.class.path" ); // all libs from System classpath | |
cp &= Server.separator.path & rc; // add the lucee-Core to classpath | |
// writeDump(cp); | |
// abort; | |
var out = java.StringWriter.init(); | |
var outWriter = java.PrintWriter.init( out, true ); | |
var cmd = "-cp #cp# #src#"; | |
outWriter.println( "Compiler Command: " & cmd ); | |
java.BatchCompiler.compile( cmd, outWriter, outWriter, javaCast( 'null', '' ) ); | |
outWriter.println( "Done." ); | |
var result = out.getBuffer().toString().trim(); | |
writeDump(result); | |
return result; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface basic | |
{ | |
public String sayHello(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
function sayHello(){ | |
return "Hello this is a basic component"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Bicycle { | |
// the Bicycle class has | |
// three fields | |
public int cadence; | |
public int gear; | |
public int speed; | |
// the Bicycle class has | |
// one constructor | |
public Bicycle(int startCadence, int startSpeed, int startGear) { | |
gear = startGear; | |
cadence = startCadence; | |
speed = startSpeed; | |
} | |
// the Bicycle class has | |
// four methods | |
public void setCadence(int newValue) { | |
cadence = newValue; | |
} | |
public void setGear(int newValue) { | |
gear = newValue; | |
} | |
public void applyBrake(int decrement) { | |
speed -= decrement; | |
} | |
public void speedUp(int increment) { | |
speed += increment; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment