Jump to: navigation, search

Difference between revisions of "Execution Environments"

Line 12: Line 12:
  
 
==Wow! Is this hard to setup?==
 
==Wow! Is this hard to setup?==
Not really.  [http://osgi.org OSGi] allows bundles to be marked with the minimum execution environment they require (see the information below).   Setting this value has two effects.
+
Not really.  [[OSGi | OSGi]] allows bundles to be marked with the minimum execution environment they require (see the [[#Setting the Execution Environment]]). Setting this value has two effects.
 
# The compiler attempts to compile your bundle against the JRE associated with the EE you choose.  For example, if you set your EE to be J2SE-1.3, then the compiler will help you stick to that and not let you use APIs which exist in other class library versions. If you choose to increase your EE level, then you are forced to explicitly do so, rather than finding out later that you did it accidentally by referencing new APIs.
 
# The compiler attempts to compile your bundle against the JRE associated with the EE you choose.  For example, if you set your EE to be J2SE-1.3, then the compiler will help you stick to that and not let you use APIs which exist in other class library versions. If you choose to increase your EE level, then you are forced to explicitly do so, rather than finding out later that you did it accidentally by referencing new APIs.
 
# The Equinox runtime will refuse to resolve/run your bundle if the current running JRE does not meet the minimum standard you specified.  For example, if you attempt to install bundle B from above (requires J2SE-1.5) on a system running Foundation 1.0, B will not resolve or run.
 
# The Equinox runtime will refuse to resolve/run your bundle if the current running JRE does not meet the minimum standard you specified.  For example, if you attempt to install bundle B from above (requires J2SE-1.5) on a system running Foundation 1.0, B will not resolve or run.
Line 18: Line 18:
 
==Which Execution Environment should I use?==
 
==Which Execution Environment should I use?==
  
As discussed above, you should seek to use the smallest EE possible.  Of course, if you actually need the functionality of J2SE-1.5, you should of course specify that EE.  Remember however that people running on J2SE-1.4, Foundation 1.*, etc. will then not be able to use your bundle.
+
As discussed above, you should seek to use the smallest EE possible.  Of course, if you actually need the functionality of J2SE-1.5, you should specify that EE.  Remember however that people running on J2SE-1.4, Foundation 1.*, etc. will then not be able to use your bundle.
  
Projects should not leave these choices to chance.  For example, the [http://eclipse.org/eclipse Eclipse Project] has explicitly identified EEs for all of their bundles.  These choices are documented in the [http://www.eclipse.org/eclipse/development/eclipse_project_plan_3_2.html#Appendix1 Eclipse 3.2 Plan]. The execution environment listed in the table is based on the needs of the bundle and the expected use scenarios for the bundle.
+
Projects should not leave these choices to chance.  Dependency structures are key parts of an architecture.  For example, the [http://eclipse.org/eclipse Eclipse Project] has explicitly identified EEs for all of their bundles.  These choices are documented in the [http://www.eclipse.org/eclipse/development/eclipse_project_plan_3_2.html#Appendix1 Eclipse 3.2 Plan]. The execution environment listed in the table is based on the needs of the bundle and the expected use scenarios for the bundle.  For example, all of the bundles key to RCP scenarios target only Foundation 1.0.
  
 
==Setting the Execution Environment==
 
==Setting the Execution Environment==
 
# Use build N20060420-0010 or later.
 
# Use build N20060420-0010 or later.
# Right click on your plug-in's <tt>MANIFEST.MF</tt> and select '''Open With...''' -> '''Plug-in Manifest Editor'''.
+
# Right click on your bundle's <tt>MANIFEST.MF</tt> and select '''Open With... > Plug-in Manifest Editor'''.
 
# Select the '''Overview''' tab.
 
# Select the '''Overview''' tab.
 
# Note the section in the lower left corner entitled '''Execution Environments'''.
 
# Note the section in the lower left corner entitled '''Execution Environments'''.
# Add your appropriate environment(s).
+
# Add your appropriate environment(s) noting the [[#Special cases]] below.
 
# Save the file.
 
# Save the file.
 
# Select the link "update the classpath and compiler compliance settings".
 
# Select the link "update the classpath and compiler compliance settings".
Line 33: Line 33:
 
# Release your changes to the repository.
 
# Release your changes to the repository.
  
 +
==Special cases==
  
==Managing Execution Environments==
+
===Foundation class libraries===
 +
Bundles that require just Foundation 1.0 should in fact list Foundation 1.0 '''and''' J2SE-1.3 in their execution environments.  This is because Foundation 1.0 is not a proper subset of 1.3 (it includes some additional javax.microedition classes).  Listing them both in essence says that only the intersection of the two EEs is valid for use in the bundle.  The situation is the same for Foundation 1.1 and J2SE-1.4.
  
 +
===Compiling against more than is required===
 +
In some cases, a bundle may optionally use function from newer execution environments if available but fall back to some other behaviour if not.  Such bundles must be compiled against the maximum EE actually used in their code.  For instance, the <tt>org.eclipse.osgi</tt> bundle uses <tt>java.nio.*</tt> classes from J2SE-1.4 if available.  It can however run against the OSGI/Minimum-1.0 EE.  As a result, it must be compiled against J2SE-1.4.
  
 +
In these cases you must list both the EE required for compilation and the absolute minimum EE for runtime in the '''Execution Environment''' section of the bundle '''Overview'''.  The EE needed for compilation against must appear '''first''' in the list. So for <tt>org.eclipse.osgi</tt>, the list (in order) is ''J2SE-1.4'' then ''OSGI/Minimum-1.0''.
  
==Special cases==
+
===XML and other optional JRE pieces===
 +
You must distinguish between core parts of a JRE and optional parts.  For example, the XML support is not a core part of the class libraries in J2SE-1.4.  There are in fact many ways to get XML support added to almost any execution environment.
  
===Foundation Class Libraries===
+
While you can gain access to these classes by specifying the related EE, that overly restricts your bundles. The better approach is to ignore this type of class when choosing the minimum EE for your bundle and instead specify Import-Package clauses in the manifest.mf of your bundleThe IDE and runtime will then find other bundles that export the needed packages and wire the bundles together.
Plug-ins that are Foundation 1.0 should in fact list Foundation 1.0 AND J2SE-1.3 in their execution environments. This is because Foundation 1.0 is not a proper subset of 1.3Listing them both will in essence say that the intersection of the  
+
 
two is valid for use in that plug-in. The situation is the same for Foundation 1.1 and J2SE-1.4.
+
This approach allows, for example, a bundle listing the J2SE-1.3 EE to use XML function as long as there is another bundle that provides (i.e., exports) the XML APIs.
 +
 
 +
==Managing Execution Environments==
 +
For the most part the Eclipse IDE manages the execution environments for you. You do however have to have the relevant JREs installed on your machine and configured into your IDE.
  
[[J9 | Getting J9]] is the easiest way to get a Foundation JRE to run or compile against.
+
Most JREs can be acquired Sun via their [http://java.sun.com main web site] or their [http://java.sun.com/products/archive/index.html handy archive site].  Note that the best source for suitable Foundation 1.* JREs is IBM's J9.  See [[J9 | Getting J9]] for more details.
  
===Compiling Against More Than Is Required===
+
When you install a new JRE, the IDE analyzes the function it provides and identifies the set of EEs it can support. The IDE distinguishes between '''exact matches''' for an EE and compatible matches. You can see all the execution environments and the JREs they match by looking at '''Window > Preferences > Java > Installed JREs > Execution Environments'''.
In some cases, a plug-in may require a higher version to compile against, but is able to run perfectly fine against a lower version. For instance, the <tt>org.eclipse.osgi</tt> bundle will use <tt>java.nio.*</tt> classes if available. So it must be compiled against J2SE-1.4 but can run on OSGI/Minimum-1.0.
+
  
In these cases the EE required to compile against must appear '''first''' in the list. So for <tt>org.eclipse.osgi</tt>, the list (in order) is ''J2SE-1.4'' then ''OSGI/Minimum-1.0''.
+
If you do not have an exact match for an EE that is specified in one of your bundles but do have a compatible match, you get a warning.  Continuing development runs the risk of using API which will not be present at runtime. If you have neither an exact or compatible match, your bundle's project will fail to compile.  
  
===XML===
+
==Standard Execution Environments==
Some bundles may think that they require an EE of J2SE-1.4 but really the only special thing that they require from the 1.4 class libraries are the JAXP XML APIs. So in these cases they can be listed as having an EE of J2SE-1.3 because they still will run ok if another bundle is providing the XML APIs.
+
The set of execution environments is extensible but the Eclipse IDE includes support for the environments set out in the OSGi R4 specification. These are summarized in the table below.

Revision as of 23:09, 20 April 2006

What are Execution Environments?

Execution environments (EEs) are symbolic representations of JREs. For example, rather than talking about a specific JRE, with a specific name at a specific location on your disk, you can talk about the J2SE-1.4 execution environment. The system can then be configured to use a specific JRE to implement that execution environment.

Execution environments are relevant both to development (compile) time and runtime.

So what does this mean to me and my bundles?

Good bundles have minimal dependencies. This allows them to be used in a wider range of situations and results in a smaller overall footprint for applications built of these bundles. The execution environment needed by your bundle is key in both situations.

Consider the different outcomes for some bundle A that requires just Foundation 1.0 and a bundle B that requires J2SE-1.5. First, A can be used in embedded devices where Foundation 1.0 is quite popular. Second, an application written entirely of bundles such as A can ship on a Foundation 1.0 JRE. This results in a 40-50MB disk/transfer footprint savings over J2SE-1.5 JREs!

Wow! Is this hard to setup?

Not really. OSGi allows bundles to be marked with the minimum execution environment they require (see the #Setting the Execution Environment). Setting this value has two effects.

  1. The compiler attempts to compile your bundle against the JRE associated with the EE you choose. For example, if you set your EE to be J2SE-1.3, then the compiler will help you stick to that and not let you use APIs which exist in other class library versions. If you choose to increase your EE level, then you are forced to explicitly do so, rather than finding out later that you did it accidentally by referencing new APIs.
  2. The Equinox runtime will refuse to resolve/run your bundle if the current running JRE does not meet the minimum standard you specified. For example, if you attempt to install bundle B from above (requires J2SE-1.5) on a system running Foundation 1.0, B will not resolve or run.

Which Execution Environment should I use?

As discussed above, you should seek to use the smallest EE possible. Of course, if you actually need the functionality of J2SE-1.5, you should specify that EE. Remember however that people running on J2SE-1.4, Foundation 1.*, etc. will then not be able to use your bundle.

Projects should not leave these choices to chance. Dependency structures are key parts of an architecture. For example, the Eclipse Project has explicitly identified EEs for all of their bundles. These choices are documented in the Eclipse 3.2 Plan. The execution environment listed in the table is based on the needs of the bundle and the expected use scenarios for the bundle. For example, all of the bundles key to RCP scenarios target only Foundation 1.0.

Setting the Execution Environment

  1. Use build N20060420-0010 or later.
  2. Right click on your bundle's MANIFEST.MF and select Open With... > Plug-in Manifest Editor.
  3. Select the Overview tab.
  4. Note the section in the lower left corner entitled Execution Environments.
  5. Add your appropriate environment(s) noting the #Special cases below.
  6. Save the file.
  7. Select the link "update the classpath and compiler compliance settings".
  8. Ensure you have no compile errors in your workspace.
  9. Release your changes to the repository.

Special cases

Foundation class libraries

Bundles that require just Foundation 1.0 should in fact list Foundation 1.0 and J2SE-1.3 in their execution environments. This is because Foundation 1.0 is not a proper subset of 1.3 (it includes some additional javax.microedition classes). Listing them both in essence says that only the intersection of the two EEs is valid for use in the bundle. The situation is the same for Foundation 1.1 and J2SE-1.4.

Compiling against more than is required

In some cases, a bundle may optionally use function from newer execution environments if available but fall back to some other behaviour if not. Such bundles must be compiled against the maximum EE actually used in their code. For instance, the org.eclipse.osgi bundle uses java.nio.* classes from J2SE-1.4 if available. It can however run against the OSGI/Minimum-1.0 EE. As a result, it must be compiled against J2SE-1.4.

In these cases you must list both the EE required for compilation and the absolute minimum EE for runtime in the Execution Environment section of the bundle Overview. The EE needed for compilation against must appear first in the list. So for org.eclipse.osgi, the list (in order) is J2SE-1.4 then OSGI/Minimum-1.0.

XML and other optional JRE pieces

You must distinguish between core parts of a JRE and optional parts. For example, the XML support is not a core part of the class libraries in J2SE-1.4. There are in fact many ways to get XML support added to almost any execution environment.

While you can gain access to these classes by specifying the related EE, that overly restricts your bundles. The better approach is to ignore this type of class when choosing the minimum EE for your bundle and instead specify Import-Package clauses in the manifest.mf of your bundle. The IDE and runtime will then find other bundles that export the needed packages and wire the bundles together.

This approach allows, for example, a bundle listing the J2SE-1.3 EE to use XML function as long as there is another bundle that provides (i.e., exports) the XML APIs.

Managing Execution Environments

For the most part the Eclipse IDE manages the execution environments for you. You do however have to have the relevant JREs installed on your machine and configured into your IDE.

Most JREs can be acquired Sun via their main web site or their handy archive site. Note that the best source for suitable Foundation 1.* JREs is IBM's J9. See Getting J9 for more details.

When you install a new JRE, the IDE analyzes the function it provides and identifies the set of EEs it can support. The IDE distinguishes between exact matches for an EE and compatible matches. You can see all the execution environments and the JREs they match by looking at Window > Preferences > Java > Installed JREs > Execution Environments.

If you do not have an exact match for an EE that is specified in one of your bundles but do have a compatible match, you get a warning. Continuing development runs the risk of using API which will not be present at runtime. If you have neither an exact or compatible match, your bundle's project will fail to compile.

Standard Execution Environments

The set of execution environments is extensible but the Eclipse IDE includes support for the environments set out in the OSGi R4 specification. These are summarized in the table below.