3 Replies Latest reply on Oct 18, 2008 5:13 PM by Ales Justin

    Adding deployer to DeploymentUnit classpath

    Stan Silvert Master

      I need to add the classes bundled with the deployer to the classpath of a VFSDeploymentUnit.

      This code doesn't work:

      public void deploy(VFSDeploymentUnit unit, JBossWebMetaData metaData) throws DeploymentException {
       URL url = getClass().getClassLoader().getResource("/");
       VirtualFile vFile = VFS.getRoot(url);
       unit.addClassPath(vFile);
      }


      getResource("/") returns a URL that looks like vfsmemory://abc1t-caplls-fmgocucl-1-fmgoe37j-d/

      But this code does work:
      public void deploy(VFSDeploymentUnit unit, JBossWebMetaData metaData) throws DeploymentException {
       BaseClassLoader classloader = (BaseClassLoader)getClass().getClassLoader();
       URL url = new URL(classloader.getName());
       VirtualFile vFile = VFS.getRoot(url);
       unit.addClassPath(vFile);
      }


      BaseClassLoader.getName() happens to return vfsfile:/C:/projects/jboss5/trunk/build/output/jboss-5.0.0.GA/server/default/deployers/jsfunit.deployer/

      I'd rather not rely on casting to BaseClassLoader and calling getName(). Is there a better way to do this?

      Stan