You can use the Solutions Java™ Management
Extensions (JMX) management bean (MBean) API to deploy and undeploy
solutions.
About this task
Using the SolutionsMXBean API, you can access Liberty server
attributes and complete various solution management tasks, such as
deploy and undeploy. The Liberty server profile provides MBeans and
corresponding management interfaces that you can use to manipulate
and monitor the server. For more information about using Liberty MBeans,
see the
WebSphere® Application
Server documentation.
Decision Server
Insights provides
MBeans for deploying and removing solutions, including the solution
deployment MBean. The management interface for the MBean is com.ibm.ia.runtime.jmx.SolutionsMXBean.
First,
you must create an MBeanServer instance for the Decision Server
Insights application
that is running on the Liberty profile, and then you can use the MBean.
Each MBean has a management interface with getter methods for the
attributes and methods for the operations. You can activate the interfaces
by calling the javax.management.JMX.newMXBeanProxy method,
which enables the MXBeans to obtain a proxy object.
- Establish an MBean server connection and create an MBean
instance. See Connecting to the MBean server for
code examples.
- Deploy a solution by using the Solutions MBean.
public static boolean installSolution(String hostName, int port, String adminUsername,
String adminPassword, String solutionFilename, String trustStorePath,
String trustStorePassword, boolean copyOnly, boolean activateOnly, boolean activateOverride)
{
boolean retVal = true;
try
{
MBeanServerConnection mbsc = getConnection(hostName, port, adminUsername, adminPassword, trustStorePath, trustStorePassword);
// determine file name and copy the file into the workarea
File solutionFile = new File(solutionFilename);
String filename = solutionFile.getName();
String externalFilename = "${server.output.dir}" + "/workarea/" + filename;
// use file transfer mbean to copy the file to the server
ObjectName objectName = new ObjectName("WebSphere:feature=restConnector,name=FileTransfer,type=FileTransfer");
Object[] params = {solutionFilename, externalFilename, false};
String[] sig = {"java.lang.String", "java.lang.String", "boolean"};
mbsc.invoke(objectName, "uploadFile", params, sig);
// use deploy mbean
objectName = new ObjectName("com.ibm.ia:type=Solutions");
SolutionsMXBean deployMBean = JMX.newMXBeanProxy(mbsc, objectName, SolutionsMXBean.class);
SolutionStatus status = deployMBean.deploySolution(externalFilename, copyOnly, activateOnly, activateOverride, false);
retVal = status.isSuccess();
}
catch (Exception exc)
{
retVal = false;
}
return retVal;
}
What to do next
You can call SolutionsMXBean methods to manage your deployed
solution. For example, activateSolution is needed on a production
server to activate the solution on all the container servers. The
redeploySolution method is only applicable on a development server.
For more information, see
SolutionsMXBean.