I am looking at https://codehaus-cargo.github.io/cargo/WebSphere+Liberty.html and I am rather stuck on how to proceed (in Java) to create a server and install a webapp into it.
The documentation (same page as above, at bottom) mentions properties but it is not clear to me how to map context name and server name to the listed properties.
Is there a good (or any) example on how to do this?
UPDATE
What I mean is how do I do the equivalent of server create myserver
command, followed by mvn liberty:deploy
into the just created myserver
, followed by server start myserver
?
The Liberty standalone cargo container will automatically create a server, so there is no need to create an API. The server name cannot be overridden though and will be called defaultServer.
To deploy an application, or to start and stop the server you can use the normal Java API. The codehause cargo website has some example code for writing a JUnit test using the Java API. I've added the code with the Liberty customization, and I added the code for how to set the context root for the application.
// (1) Optional step to install the container from a URL pointing to its distribution
Installer installer = new ZipURLInstaller(
new URL("http://repo1.maven.org/maven2/com/ibm/websphere/appserver/runtime/wlp-javaee7/8.5.5.9/wlp-javaee7-8.5.5.9.zip"));
installer.install();
// (2) Create the Cargo Container instance wrapping our physical container
LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory().createConfiguration(
"liberty", ContainerType.INSTALLED, ConfigurationType.STANDALONE);
InstalledLocalContainer container =
(InstalledLocalContainer) new DefaultContainerFactory().createContainer(
"liberty", ContainerType.INSTALLED, configuration);
container.setHome(installer.getHome());
// (3) Statically deploy some WAR (optional)
WAR war = new WAR("cargo.war");
// (4) Set the context root for the application
war.setContext("/myContext");
configuration.addDeployable(war);
// (5) Start the container
container.start();
The properties can be set using the LocalConfiguration interface. You would call setPropertyValue using the right key. The property keys are available on constant interfaces like the GeneralPropertySet.