| J2JS | ||||||||||||||||||||||||||||||||||||||||||||||
| Home > Docs > Compiler Usage | ||||||||||||||||||||||||||||||||||||||||||||||
1. Compiler UsageThe J2JS cross-compiler translates Java class files into JavaScript code and assembles reachable code into an assembly. To boost performance, J2JS is incremental by performing dependency checking based on existence/modification times. It is important to understand that the assembler will ignore all unreachable code. The decision on reachability is based on a static code analysis and a set of entry points: Only those methods are reachable which can be traced back to a method declared as an entry point. 2. ConfigurationThe J2JS cross-compiler is configured with an xml string. This string can have the following attributes.
3. Standalone InvokationThe cross-compiler can be invoked directly on the command line, for example set applCLASSPATH=lib/j2js.jar;lib/bcel.jar java -cp %applCLASSPATH% j2js.compiler.Compiler conf/helloworld1.xml Extracted from /projects/j2js-Demos/compile.batThe single argument must be the path to a file containing the xml-configuration. 4. Ant Invokation1. Task DeclarationThe j2js compiler can be executed as an Ant task. See j2j2-Demos/build.xml how to declare this task. 2. Build Example
<target name="HelloWorld1">
<j2js
baseDir="${basedir}"
targetDir="build/site"
classPath="build/classes; ${j2js-Runtime.dir}/build/classes"
webPage="src/site/HelloWorld1.html"
onLoad="j2js.demo.HelloWorld1#main(java.lang.String[])"
junkSize="30kB"
compression="true"
generateLineNumbers="false"
cacheFile="build/j2js.cache" />
</target>
Extracted from /projects/j2js-Demos/build.xml
compiles all required classes and creates in the build directory
an assembly containing all methods reachable through the specified entry point.
5. About SignaturesSignatures play an important role for the configuration of J2JS. 1. Method SignaturesA method signature is a string of the form
Examples are
2. Class SignaturesA class signature is the name of a class, for example
3. Package SignaturesA package signature is the name of a package followed by the wildcard '.*', for example
4. Pre-Reachable Signatures
There are three ways to specify reachable signatues: Using the
The signatures specified in 1. Unconditional ReachabilityUnconditionally reachable signatures are typically used by the JavaScript JVM, and thus must be recognized by the static code analyser. j2js.preTaintedSignatures = \
java.lang.NullPointerException#<init>(java.lang.String); \
java.lang.RuntimeException#<init>(java.lang.String); \
java.lang.Throwable#printStackTrace(); \
java.lang.Throwable#fillInStackTrace(); \
java.lang.Throwable#toString(); \
java.lang.String#init(); \
java.lang.System#invoke(java.lang.String,java.lang.String); \
java.lang.Class$AnnotationInvocationHandler#invoke(\
java.lang.Object,\
java.lang.reflect.Method,java.lang.Object[]); \
java.lang.reflect.Proxy#invoke(\
java.lang.reflect.Proxy,\
java.lang.String,java.lang.Object[]); \
j2js.client.Engine#getEngine();
Extracted from file:/D:/workspace/j2js-Compiler/src/resources/j2js.properties
2. Instancing Based ReachabilityReachability based on instancing means that a signature becomes automatically reachable if the code analyser discovers that an object of the associated class is instantiated. j2js.taintIfInstantiated = \
*#handleEvent(*); \
*#compare(java.lang.Object,java.lang.Object); \
*#invoke(*)
Extracted from file:/D:/workspace/j2js-Compiler/src/resources/j2js.properties
| ||||||||||||||||||||||||||||||||||||||||||||||
| Last build on Sat Jan 03 11:06:48 CET 2009 | ||||||||||||||||||||||||||||||||||||||||||||||