Skip to content

Running the Examples

Makopoppo edited this page May 15, 2016 · 8 revisions

The Java Client API includes several packages containing examples. This topic tells you how to access and run the examples in two ways: By importing a copy of the Java Client API source code into Eclipse, or by compiling and running the example source code included in the pre-packaged distribution.

It is assumed you already have an installation of MarkLogic Server.

Note: Some of the Cookbook examples (com.marklogic.client.example.cookbook) depend on one another, so the order in which you run them matters. For example, the DocumentRead example assumes the DocumentWrite example has already run. See AllCookbookExamples.java for a safe ordering.

From Project Source, Using Eclipse

Use these instructions to run the examples when working with Java Client API sources in the Eclipse IDE.

  1. Inside Eclipse, select Import... from the File menu and navigate to the project root to import the project into Eclipse.
  2. Create the necessary users then modify your copy of src/main/resources/Example.properties to match your MarkLogic connection information, using the instructions in src/main/resources/example/README.txt.
  3. To run an example, right-click on it in the Package Explorer and select Run As...Java Application. You will need to select the class name to run.

From a Pre-Packaged Distribution, Using the Command Line

Use these instructions to run the examples when working with a pre-built Java Client API library, such as the ZIP file available from developer.marklogic.com. The example source code is included in the example/ subdirectory after you unpack the ZIP file.

  1. Download and unzip the Java Client API library package to a location of your choice.
  2. Ensure that you have a compatible Java JDK on your path.
  3. Modify java-client-api-_version_/example/Example.properties to match your MarkLogic connection information, as described in java-client-api-version/example/README.txt.
  4. Compile the examples located in java-client-api-version/example. (Some of the examples in com.marklogic.client.example.handle require additional libraries. For details, see example/README.txt.)
  5. Run an example with jars in the lib/ directory on the classpath.

For example, the following commands compile all the Cookbook examples and run the DocumentWrite example:

cd java-client-3.0.1/example
javac -cp "../lib/*" com/marklogic/client/example/cookbook/*.java
java -cp ".:../lib/*" com.marklogic.client.example.cookbook.DocumentWrite