Install the Splunk SDK for Java

To install the SDK, you just need to build it using Ant. Open a command prompt at the root of the Splunk® SDK for Java directory (/splunk-sdk-java) and enter:

ant

After you build the SDK, a /splunk-sdk-java/dist directory is created, containing these .jar files:

  • splunk.jar contains the Splunk SDK for Java. Add this to your build path to use the SDK.
  • opencsv-2.3.jar contains third-party tokenizers for parsing results for CSV output. Add this to your build path to display search results in CSV format using the ResultsReaderCsv class.
  • gson-2.1.jar contains third-party tokenizers for parsing results for JSON output. Add this to your build path to display search results in JSON format using the ResultsReaderJson class.

To remove all build artifacts from the repository, enter:

ant clean

To build the documentation for the SDK, enter:

ant javadoc

If you are interested in more control of the build process, see the build.xml file. You can also type the following command from anywhere in the repository to find the root build file:

ant {target} -find

Use Maven

You can use Apache Maven to build your Splunk SDK for Java projects. With a few updates to your project's pom.xml file, it will retrieve all necessary dependencies and seamlessly build your project.

To add the Splunk SDK for Java .JAR file as a dependency:

  1. Add the repository to your project's pom.xml file:

    <repositories>
      ...
      <repository>
        <id>splunk-artifactory</id>  
        <name>Splunk Releases</name>
        <url>http://splunk.artifactoryonline.com/splunk/ext-releases-local</url>
      </repository>
    </repositories>
  2. Add the dependency to the pom.xml file:

    <dependencies>
      ...
      <dependency>
        <groupId>com.splunk</groupId>
        <artifactId>splunk</artifactId>
        <version>1.6.0.0</version>
      </dependency>
    </dependencies>

Be sure to update the version number to match the version of the Splunk SDK for Java that you are using.

Note: You can make similar changes to use Ivy or Gradle as well.