Skip to content

Instantly share code, notes, and snippets.

@dblevins
Created August 14, 2009 21:39
Show Gist options
  • Save dblevins/168121 to your computer and use it in GitHub Desktop.
Save dblevins/168121 to your computer and use it in GitHub Desktop.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.openejb;
import org.apache.openejb.assembler.Deployer;
import org.apache.openejb.assembler.classic.AppInfo;
import org.apache.openejb.config.RemoteServer;
import org.junit.Test;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
public class DeployUndeploy {
private Context ctx;
private Deployer deployer;
public boolean init() {
try {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
props.put(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201");
ctx = new InitialContext(props);
deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
return true;
} catch (NamingException e) {
e.printStackTrace();
return false;
}
}
@Test
public void deployundeploy() throws Exception {
String appPath = "/tmp/openejb-examples-3.1.1/simple-stateless/target/simple-stateless-1.0.jar";
System.setProperty("openejb.home", "/tmp/openejb-3.1.1");
String[] param = new String[1];
param[0] = "start";
RemoteServer.main(param);
init();
list();
// Deploy the app
AppInfo info1 = deployer.deploy(appPath);
System.out.println("Deployed " + info1.jarPath);
list();
// Undeploy it
deployer.undeploy(info1.jarPath);
System.out.println("Undeployed " + info1.jarPath);
list();
// Deploy the app again
AppInfo info2 = deployer.deploy(appPath);
System.out.println("Deployed " + info2.jarPath);
list();
// Undeploy it again
deployer.undeploy(info2.jarPath);
System.out.println("Undeployed " + info2.jarPath);
list();
param = new String[1];
param[0] = "stop";
RemoteServer.main(param);
}
private void list() {
System.out.println();
// List apps
for (AppInfo app : deployer.getDeployedApps()) {
System.out.println(" app: " + app.jarPath);
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment