Get Started with Java

This section describes how to develop some interactions with the Curare API for Java.

Prerequisites

curare-api-java requires Java 8 or higher.

Get the API token

See the related guide.

Setup Maven dependency

To add the necessary dependency, edit your pom.xml and add the curare-api-java dependency immediately below the parent section:

<dependencies>
    <dependency>
        <groupId>fr.inrae.curare</groupId>
        <artifactId>curare-api-java</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

Setup configuration

Configuration can be loaded from 3 ways:

  • environment variables,
  • system properties,
  • configuration file,
  • manually.

More details in the configuration guide.

Example, write an .env file in the root of your project:

CURARE_API_TOKEN=12345678-1234-1234-1234-123456789012
CURARE_INSTANCE_URL=https://data-preproduction.inrae.fr
CURARE_DEFAULT_DATAVERSE=curare

Write the code

// Load configuration
final DataverseConfiguration config = new DataverseConfiguration();
config.loadDotEnv(); // or use another method to load configuration, see the configuration guide
// Check configuration
if (!config.check()) {
    LOGGER.error("CURARE API configuration is invalid");
    System.exit(1);
}
// Initialize API client
final DataverseClient client = new DataverseClient(config);
// Use the API

See the API guide for details.