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 librariessrc
—contains the PubSub+ Java API sample files, including patterns and snippetssemp-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.
- 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
- To create the class path files for Eclipse, run the following command:
C:\Users\JohnSmith\JavaRepository\solace-samples-java-main> gradlew eclipse
- 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