Using the Java API Examples

You can obtain code examples for the PubSub+ Messaging API for Java from the Solace Developer Hub. From the Solace Developer Hub, you can access examples in Git. The Git project contains the following directories:

  • lib—Java libraries
  • src—contains the PubSub+ Java API sample files, including patterns and snippets
  • semp-rest-api—contains instructions on how to set up the RESTful Management API, SEMP

Building the Project

The following is an example of how to build your project. The examples are shown in Windows Command Prompt, but you use can use any operating system that supports Java.

  1. In the Command Prompt, navigate to the source directory and enter the following command to build the project:
    C:\Users\JohnSmith\JavaRepository\solace-samples-java-main> gradlew clean assemble
    
  2. To create the class path files for Eclipse, run the following command:
    C:\Users\JohnSmith\JavaRepository\solace-samples-java-main> gradlew eclipse
  3. To add the project directory to your Eclipse IDE, select the File menu, then select Import > Import Existing Projects Into Workspace.

Running the Examples

You can run the examples from Eclipse or you can run the Java files from CLI.

To run the Java samples from the CLI, navigate to the bin directory and type the name of the Java file you want to execute with the required parameters.

To see the parameters that you can use, type the name of the Java file and press Enter. For example, in the Windows Command Prompt you can provide a host/port, VPN, user name, and password when you run HelloWorld.java:

C:\Users\Solly\JavaRepository\solace-samples-java-main\build\staged\bin> HelloWorld
HelloWorld host:port message-vpn client-username password