6.5 Class Loading Commands Reference
Prev | 6. Equinox Console | Next

## 6.5 Class Loading Commands Reference

This section contains reference information about the class loading commands clhas, clexport, and clload.

### clhas command

Use the `clhas` command to list the classes contained in the bundles deployed to VTS and to solve class loading issues.

The command accepts as a parameter the fully qualified class name (in the form package.class).

A bundle is listed only if the class can be loaded. If the class is successfully loaded a check is made if the loading was delegated to another bundle. The command lists only the leaves in the class loading hierarchy - i.e. the bundles that actually contain the class and not the ones that delegate to another bundle via import/require mechanisms.

The following examples show how to use this command.

Use the `clhas` to view all bundles that contain `Servlet` class:

    osgi> clhas javax.servlet.Servlet

    Bundles containing [javax.servlet.Servlet]:
      14    com.springsource.javax.servlet

The following example shows how to identify a possible `ClassCastException` due to wrong packaging:

    osgi> clhas javax.servlet.Servlet

    Bundles containing [javax.servlet.Servlet]:
      66    myapp
      14    com.springsource.javax.servlet

It's obvious that the `javax.servlet` package should not be present in `myapp` application and its packaging has to be changed. This problem can often be seen in WAR or web bundles that package Servlet/JSP classes by accident.

### clexport command

Use the `clexport` command to list the bundles that export a class or package.

The command accepts as a parameter the fully qualified class name (in the form package.class).

Additional check if the provided class is actually contained in the bundle is performed. If the class is not found in a bundle, but its package is exported then a hint `[class not found, package only]` is displayed.

The following examples show how to use this command.

Use the `clexport` to view all bundles that contain `Servlet` class:

    osgi> clexport javax.servlet.Servlet

    Bundles exporting [javax.servlet.Servlet]:
      14    com.springsource.javax.servlet

If a bundle exports a package but the requested class is not contained the output of the command will be similar to this:

    osgi> clexport javax.servlet.ServletX

    Bundles exporting [javax.servlet.ServletX]:
      14    com.springsource.javax.servlet     [class not found, package only]

### clload command

Use the `clload` command to list the bundles that can load a class or to check if a specific bundle can load a class.

The command accepts as a parameter either:

- the fully qualified class name (in the form package.class)

- the fully qualified class name (in the form package.class) and the symbolic name or id of the bundle that has to be tested

The command lists not only the bundle that successfully loaded the class, but also the one that actually provides the class. This is visualized with hints like `[exported by 14 com.springsource.javax.servlet]`.

The following examples show how to use this command.

You can use the `clload` to view all bundles that can load `Servlet` class:

    osgi> clload javax.servlet.Servlet

    Successfully loaded [javax.servlet.Servlet] from:
      56    com.springsource.org.apache.taglibs.standard
                    [exported by 14 com.springsource.javax.servlet]
      54    org.eclipse.virgo.apps.admin.web
                    [exported by 14 com.springsource.javax.servlet]
      19    com.springsource.org.apache.commons.fileupload
                    [exported by 14 com.springsource.javax.servlet]
      <... remainder omitted ...>

If a bundle has to be tested, then its id can be used as a command parameter:

    osgi> clload javax.servlet.Servlet 19

    Successfully loaded [javax.servlet.Servlet] using class loader from:
      19    com.springsource.org.apache.commons.fileupload
                    [exported by 14 com.springsource.javax.servlet]

Or the same class load test with the symbolic name of the bundle:

    osgi> clload javax.servlet.Servlet com.springsource.org.apache.commons.fileupload

    Successfully loaded [javax.servlet.Servlet] using class loader from:
      19    com.springsource.org.apache.commons.fileupload
                    [exported by 14 com.springsource.javax.servlet]

Prev | Up | Next
6.4 Class Loading Commands | Home | 7. The Web Admin Console