GlassFish 中的jsr88

由于最近遇到了相关问题,所以看了看jsr88

什么是jsr88?
由于存在许多的AppServer,各个Server可部署的应用的格式也许各不相同,那为了适应不同的Server,开发者需要更换应用的形式,才可以部署到不同的AppServer上。为此,JCP提出了JSR88
Java Application Deployment(JSR 88)来解决这个问题.
更详细的说明,看这里:http://www.ibm.com/developerworks/cn/opensource/os-ag-remotedeploy/
有了jsr88后,各个AppServer只要指定
J2EE-DeploymentFactory-Implementation-Class:xxx.xxx.XXXFactory
即可。相应的部署需要时会调用指定的Factory

GlassFish中的jsr88指定为
org.glassfish.deployapi.SunDeploymentFactory

具体加载:
   protected void initialize() {
                
        File[] elligibleFiles = getListOfDeploymentFactoryFiles();
        if (elligibleFiles==null) {
            return;
        }
           
        for (int i=0;i<elligibleFiles.length;i++) {
            try {
                installDeploymentFactory(elligibleFiles[i]);
            } catch(Exception ioe) {
                ioe.printStackTrace();
                DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.deplyomentManagerLoadFailure",
                    new Object[] {elligibleFiles[i].getName()});
            }
        }        
    }
获取到指定的类后加载
public void installDeploymentFactory(File installedDM) throws IOException {
        
        if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
            DOLUtils.getDefaultLogger().fine("Installing Deployment factory = " 
                    + installedDM.getAbsolutePath());
        }
        
        // let's check first that we indeed have a valid 
        // deployment manager implementation
        
        /*
         *Declare the JarFile and Manifest but populate them inside the first try block.  This way the 
         *jar file can be closed right away to conserve resources.
         */
        JarFile jarFile = null;
        Manifest m = null;
        try {
            jarFile = new JarFile(installedDM);
            m = jarFile.getManifest();
        } finally {
            /*
             *The jarFile.close can throw IOException, but this method also throws that exception so there is no
             *need to catch it and wrap it here in the finally clause.
             */
            jarFile.close();
            jarFile = null;
        }
        String className = m.getMainAttributes().getValue(J2EE_DEPLOYMENT_MANAGER);
        URL[] urls = new URL[]{installedDM.toURI().toURL()};
        URLClassLoader urlClassLoader = new java.net.URLClassLoader(urls, getClass().getClassLoader());
        Class factory = null;
        try {
            factory=urlClassLoader.loadClass(className);
        } catch (ClassNotFoundException cnfe) {
            DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.deplyomentManagerLoadFailure",
                new Object[] {"Unable to load declared DeploymentManagerFactory"});
            throw new IllegalArgumentException(className + " is not present in the " + installedDM.getName());
        }
        
        // Ok we have the class, let's instanciate it, check it and 
        // if everything is fine, register it to the DeploymentFactoryManager
        Object df = null;
        try {            
            df = factory.newInstance();
        } catch (Exception ie) {
            DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.deplyomentManagerLoadFailure",
                    new Object[]{className});
            ie.printStackTrace();
            throw new IllegalArgumentException("Cannot install " + installedDM.getName());
        }
        if (df instanceof DeploymentFactory) {
            DeploymentFactoryManager.getInstance().registerDeploymentFactory((DeploymentFactory) df);
        } else {
            throw new IllegalArgumentException("The " + className + 
                " declared as a DeploymentFactory does implement the DeploymentFactory interface");
        }
    }

getListOfDeploymentFactoryFiles()获取指定目录下的jsr88的实现指定类
在指定的jar包的META-INF/MANIFEST.MF文件中指定了实现类:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 1.5.0_22-b03 (Sun Microsystems Inc.)
J2EE-DeploymentFactory-Implementation-Class: org.glassfish.SunDeploymentFactory
Specification-Title: Java Platform, Enterprise Edition Specification
Specification-Vendor: Sun Microsystems, Inc.
Specification-Version: 5.0


猜你喜欢

转载自chainhou.iteye.com/blog/1749932
今日推荐