Wednesday, October 21, 2009

Execution Environment and javac entries

Execution Environment
Execution Environments have been explained in detail in this article. And from PDE API tooling perspective it has been explained here. In one line, EE represents the JRE. It is a set of properties, each marking a level of compliance. I am reproducing this table from 'Setting the Compilation Environment' help page.


Environment
Source
Target
CDC-1.0/Foundation-1.0
1.3
1.1
CDC-1.1/Foundation-1.1
1.3
1.2
OSGi/Minimum-1.0
1.3
1.1
OSGi/Minimum-1.1
1.3
1.2
JRE-1.1
1.1
1.1
J2SE-1.2
1.2
1.1
J2SE-1.3
1.3
1.1
J2SE-1.4
1.3
1.2
J2SE-1.5
1.5
1.5
JavaSE-1.6
1.6
1.6
PersonalJava-1.1
1.1
1.1
PersonalJava-1.2
1.1
1.1
CDC-1.0/PersonalBasis-1.0
1.3
1.1
CDC-1.0/PersonalJava-1.0
1.3
1.1
CDC-1.1/PersonalBasis-1.1
1.3
1.2
CDC-1.1/PersonalJava-1.1
1.3
1.2

There are more properties and are provided by org.eclipse.jdt.core

org.eclipse.jdt.launching plug-in provides an extension point (id = org.eclipse.jdt.launching.executionEnvironments) for contributing EEs. JDT Launching plug-in also extends it and provides the EEs that are listed in the above table. If you really want to see the code then check out JavaCore.java and CompilerOptions.java in org.eclipse.jdt.core plug-in.

Manifest.MF

The execution environment for a bundle can be defined in the Manifest.MF file. A typical entry for Java 1.4 environment will look like this.

Bundle-RequiredExecutionEnvironment: J2SE-1.4

The manifest editor provides an easier way on the Overview tab.


Execution Environment section on Overview page of Manifest Editor

The Add button opens a selection dialog with the list of available execution environments (contributed to the extension point org.eclipse.jdt.launching.executionEnvironments). By default the list is same as those listed in the table above.

jre.compilation.profile
The execution environment in build.properties is mentioned using the jre.compilation.profile entry. It takes same value as BREE entry in manifest.MF. Thus, the entry for Java 1.4 will look like this.

jre.compilation.profile = J2SE-1.4

javacSource, javacTarget and javacWarnings
These entries can be used to override the jre.compilation.profile entry in build.properties. A certain EE mandates a particular version for Java source and generated class file compliance. These versions can be overridden using these entries. These entries can be used without jre profile entry as well. If you just want to specify the java source version then only javacSource entry will suffice.

Looking at the table above we can see that J2SE-1.4 is Java source at version 1.3 and class files version 1.2 compliant. This can be mentioned in build.properties as

javacSource = 1.3
javacTarget = 1.2

Please note that the above two entries are not equivalent to jre profile entry for J2SE-1.4. This is because an EE is other properties too like system packages, boot delegation, assert and enum identifiers. See the schema description for the EE extension point discussed above.

Eclipse uses batch compiler to build the plug-ins. It is located inside org.eclipse.jdt.core. Since version 3.2, it is also available as separate download - ecj.jar - Eclipse Compiler for Java. The batch compiler accepts many options and a list and details can be found here. The javacSource and javacTarget entries map to -source and -target options.

javacWarnings.<library> entry is used to pass the warning options (-warn) to the compiler. The entry to suppress warnings for assert and enum identifiers in library.jar will look like this

javacWarnings.library.jar = -assertIdentifer, -enumIdentifier


No comments:

Post a Comment