1. glassfish
  2. GLASSFISH-20856

org.glassfish.main.deployment:deployment-client cannot be used WITHIN the GlassFish container


    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s:, 4.0
    • Fix Version/s: None
    • Component/s: deployment
    • Labels:


      The GlassFish JSR-88 Deployment Client 4.0 (and apparently also does not work when deployed as part of a module to a GlassFish container (say within an EAR). When running the following code within the deployed module:

      final DeploymentFactory df = new org.glassfish.deployapi.SunDeploymentFactory();
      final DeploymentManager dm = df.getDeploymentManager("deployer:Sun:AppServer::localhost:4848", "admin", "");
      try {
          final Target[] targets = dm.getTargets();
          Logger  .getLogger(Jsr88UpdateInstaller.class.getName())
                  .log(Level.INFO, "Found {0,choice,0#No targets|1#one target|1<{0} targets}.", targets.length);
          for (final Target target : targets) {
              Logger  .getLogger(Jsr88UpdateInstaller.class.getName())
                      .log(Level.INFO, "Target {0}: {1}.", new Object[] { target.getName(), target.getDescription() });
          for (final ModuleType mt : new ModuleType[] { ModuleType.EAR, ModuleType.EJB, ModuleType.CAR, ModuleType.RAR, ModuleType.WAR }) {
              final TargetModuleID[] tmids = dm.getRunningModules(mt, targets);
              if (null == tmids) continue;
              for (final TargetModuleID tmid : tmids) {
                  Logger  .getLogger(Jsr88UpdateInstaller.class.getName())
                          .log(Level.INFO, "Target module ID {0} .", tmid.toString());
      } finally {

      Then it should list the available modules. However, it fails on the call to DeploymentManager.getRunningModules(ModuleType, Target[]) with the following exception:

      javax.enterprise.deploy.spi.exceptions.TargetException: Error getting required modules
      	at org.glassfish.deployapi.SunDeploymentManager.getModules(
      	at org.glassfish.deployapi.SunDeploymentManager.getRunningModules(

      When debug-stepping through the code, I see it throws and discards a ClassCastException saying that it cannot cast org.glassfish.deployapi.TargetImpl to the same class! This hints that there is an issue with the class loader configuration. Further investigating the issue, I found the following declaration in META-INF/MANIFEST.MF:

      Export-Package: org.glassfish.deployment.client;uses:="org.glassfish.a

      Apparently, the package org.glassfish.deployapi is missing here. I don't know much about OSGI, but I think this is the reason why the TargetImpl class gets defined by two different class loaders.

      When googling for this ClassCastException, you will find that this is quite a frequent issue, e.g. when running Jenkins on GlassFish. Furthermore, it's a showstopper for using the Deployment Client from within the GlassFish container.


        There are no comments yet on this issue.


          • Assignee:
            Hong Zhang
            Christian Schlichtherle
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: