users@glassfish.java.net

Re: Deploy EAR / WAR / RAR to remote server / domain

From: <glassfish_at_javadesktop.org>
Date: Sat, 07 Apr 2007 13:23:08 PDT

Hi Tim and Sheerdar,

Thanx for the quick response. I've been digging a bit into this JSR 88. It looks promissing, specially that it is standard JEE 5 and thus should work towards all compliant JEE 5 AS.

I managed to get connected to with a remote machine using the following code. (Based on the code found at this thread http://forum.java.sun.com/thread.jspa?threadID=614719&messageID=3527542 thanx vijaysr1)
This is nice as I will be able to integrate the code into an ant task i.e.

The code resulted in this, which looks promissing. Remains the actual deployment coding. Any ideas / examples on this?

DF = com.sun.enterprise.deployapi.SunDeploymentFactory_at_506411
DF.getInterfaces = [interface javax.enterprise.deploy.spi.factories.DeploymentFactory]
DM = com.sun.enterprise.deployapi.SunDeploymentManager_at_12a54f9
DM.targets = [bla.blablabla.nl:4848_server]

package nl.tjosoft.j2ee.deploy;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;

import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
import javax.enterprise.deploy.spi.DeploymentManager;
import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
import javax.enterprise.deploy.spi.factories.DeploymentFactory;

public class RemoteDeployer {
        private DeploymentManager dm;

        public RemoteDeployer(String aRemoteHost, String aRemotePort, String anAdminUser, String anAdminPwd)
                throws DeploymentManagerCreationException {
// Temp removed obtaining J2EE-DeploymentFactory-Implementation-Class from meta-attribute.
// The jar is not standard part of the GF runtime for WTP.
                //File file = new File(System.getProperty("installRoot")
                // + File.separator+ "lib" + File.separator + "deployment"
                // + File.separator + "sun-as-jsr88-dm.jar");
                //Manifest mf = new java.util.jar.JarFile(file).getManifest();
                String className = "com.sun.enterprise.deployapi.SunDeploymentFactory";// mf.getMainAttributes().getValue("J2EE-DeploymentFactory-Implementation-Class");
                //URL[] urls = new URL[]{file.toURL()};
                URL[] urls = new URL[]{};
                URLClassLoader urlClassLoader = new java.net.URLClassLoader(urls, getClass().getClassLoader());

                Class factory = null;
                try {
                        factory=urlClassLoader.loadClass(className);
                } catch (ClassNotFoundException cnfe) {
                        cnfe.printStackTrace();
                }

                Object df = null;
                try {
                        df = factory.newInstance();
                } catch (Exception ie) {
                        ie.printStackTrace();
                }
                
                System.out.println("DF = "+df);
                System.out.println("DF.getInterfaces = "+Arrays.asList(df.getClass().getInterfaces()));
                
                if (df instanceof DeploymentFactory) {
                        DeploymentFactoryManager.getInstance().registerDeploymentFactory((DeploymentFactory) df);
                        dm = DeploymentFactoryManager.getInstance().getDeploymentManager("deployer:Sun:AppServer::"+aRemoteHost+":"+aRemotePort,
                                        anAdminUser, anAdminPwd);
                        
                        System.out.println("DM = "+dm);
                        System.out.println("DM.targets = "+Arrays.asList(dm.getTargets()));
                }
        }
        
        public static void main(String[] args) throws Exception {
                String host = args.length>0 ? args[0] : "bla.blablabla.nl";
                String port = args.length>1 ? args[1] : "4848";
                String adminUsr = args.length>2 ? args[2] : "admin";
                String adminPwd = args.length>3 ? args[3] : "blabla";
                String module = args.length>4 ? args[4] : "test.ear";
                
                RemoteDeployer rd = new RemoteDeployer(host, port, adminUsr, adminPwd);
                
                
        }
        
}
[Message sent by forum member 'eltjo' (eltjo)]

http://forums.java.net/jive/thread.jspa?messageID=211464