Home/Field Guide/Practice & reference
LAB 04
Deploy an OSGi Gogo command
Build a DS component, prove command registration, and trace a deployment failure.
Before you begin
Use a local, target-aligned Workspace and authorized Gogo access. Create modules/hello-command/ and use the exact Workspace target supported for your distribution. This example uses a standalone OSGi DS component and no servlet or portlet imports.
1. Define the module
Save the dependency in build.gradle. This is the Portal variant. For DXP, use the matching release.dxp.api dependency supported by your Workspace target.
dependencies {
compileOnly group: "com.liferay.portal", name: "release.portal.api"
}
Save the following as bnd.bnd.
Bundle-Name: Partner Hello Command
Bundle-SymbolicName: guide.partner.hello
Bundle-Version: 1.0.0
2. Register a command
Save as src/main/java/guide/partner/hello/HelloCommand.java.
package guide.partner.hello;
import org.osgi.service.component.annotations.Component;
@Component(
property = {
"osgi.command.function=hello",
"osgi.command.scope=partner"
},
service = HelloCommand.class
)
public class HelloCommand {
public String hello() {
return "Partner Hub is ready.";
}
}
3. Deploy and observe
./gradlew :modules:hello-command:deploy
In Gogo, run lb and locate the bundle, then use scr:list to locate the component. Run partner:hello and expect Partner Hub is ready. A delayed DS component may activate on first use. Use scr:info guide.partner.hello.HelloCommand to inspect it.
To rehearse a diagnosis, change only the osgi.command.function property to welcome and redeploy. The bundle and component can be healthy while partner:hello no longer resolves. Match the command properties to the actual invocation, then restore the original. If the bundle stays installed, use diag <bundleId> and inspect package wiring before changing dependencies.
