To convert an enterprise application to an OSGi application,
you convert the enterprise archive (EAR) file to an enterprise bundle
archive (EBA) file. Before you do this, consider whether the contents
of the EAR file are suitable for automatic conversion.
Some enterprise applications can be converted automatically to
an OSGi application, some require manual conversion steps, and some
require only partial conversion.
It is assumed that the enterprise application that you convert
is a single EAR file.
- You can automatically convert an enterprise application that contains
only web modules. An EAR file that contains only web application archive
(WAR) files can be converted to an EBA file. When you import the EBA
file as an asset, the WAR files are automatically converted to web
application bundles (WABs).
- You cannot automatically convert an enterprise application that
contains utility JAR files. These utility JAR files might be in the
EAR file, that is, referenced by using a Class-Path attribute, or
in an external location, that is, referenced by using an Extension-List
attribute. You need manual conversion steps.
- You cannot automatically convert an enterprise application that
contains Enterprise JavaBeans (EJB).
You can convert the EAR file to an EBA file and import that file as
an asset. However, the EJB JAR files are not converted, and the EJB
function is not directly accessible in the EJB container. You need
manual conversion steps.
With a large or complex application, it might be appropriate to
convert only aspects of the application. For example, the following
areas of the application might be suitable for conversion:
- Areas that use a utility JAR file, so that the application footprint
is reduced.
- Areas that benefit from the version control capabilities of OSGi.
- Areas that benefit from the dependency injection approach of OSGi.
Manual conversion steps
If an enterprise
application contains web modules and utility JAR files, and the utility
JAR files are referenced by using a Class-Path attribute or an Extension-List
attribute, conversion requires manual steps. You can do one of the
following:
- Move the JAR file to the WEB-INF/lib directory
of the WAR file. This option is simple, but you do not get all the
benefits of OSGi. For example, the same library file might be duplicated
in many WAR files.
- Convert the JAR file to an OSGi bundle. You can then include the
bundle directly in the EBA file, or add it to a bundle repository
and include it by reference in the EBA file. If you add the bundle
to a repository, it is available to other OSGi applications, and can
reduce the application footprint.
If an enterprise application contains EJB modules, you
must rewrite the application logic. For example, you must remove any
annotations and references to EJBs from a servlet, because an OSGi
bundle or a web application bundle (WAB) cannot directly look up and
invoke an EJB. It is possible to change the application to interact
with EJB modules by sending Java™ Message
Service (JMS) messages so that the EJBs or message driven beans (MDBs)
can retrieve those messages from those destinations and reply to them.
Also, all necessary JAR files must be in the WEB-INF/lib directory
of the WAR file, or be converted to OSGi bundles.
If an enterprise
application contains EJB modules, another approach is to consider
using a Service Component Architecture (SCA) environment and specify
bindings in that environment.
After you complete manual conversion
steps, you can continue with automatic conversion.
Migration of Java 2
security settings
When you migrate an application from Java EE to OSGi, any existing was.policy file is converted into a permissions.perm file to be used with the OSGi permissions framework, and all permissions
are promoted to the application level. If you need finer granularity, you can modify the file after conversion. For more information,
see Java 2 security and OSGi Applications.