This section is intended to help Java developers get started using the Fauna Java driver for application development.

Current version and repository location

Current stable version




  • Java 11

  • Jackson for JSON parsing.


Download from the Maven central repository:


Example application

The following example code runs a bare-bones Java application which creates a new document in a collection called People.


  • A Fauna account. If you don’t have one, see the dashboard quick start for help getting set up.

  • A supported version of Java and the Fauna Java driver.

  • Maven 3.6.x, or higher.


  1. Navigate to the Fauna Dashboard

    Log in to your Fauna account at Fauna Dashboard if you’re not already logged in.

  2. Create a new database

    Click NEW DATABASE. Select the Classic region group.

  3. Create a new collection

    Click NEW COLLECTION. Name your new collection People and save it.

  4. Create an access key

    Click SECURITY in the left-side navigation menu. Create a new key for your database. Be sure to save the key’s secret in a safe place, as it is only displayed once.

  5. Create a local environment variable with your access key’s secret

    On MacOS and Linux systems, enter the following in a terminal window:

    export FAUNADB_SECRET=<your-secret>

    For Windows systems, enter the following in a terminal window:

    set FAUNADB_SECRET=<your secret>

    For either example, replace <your secret> with the secret for the access key that you created.

  6. Create a project folder using the standard directory layout

    In a terminal window, in an empty folder, run the following command:

    mvn archetype:generate \
      -DgroupId=example \
      -DartifactId=example \
      -DarchetypeArtifactId=maven-archetype-quickstart \
      -DarchetypeVersion=1.4 \

    Then enter the folder:

    cd example
  7. Edit the pom.xml file

    With your preferred editor, replace the contents of the pom.xml file with the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns=""
  8. Create a local application file

    With your preferred editor, replace the contents of the src/main/java/example/ file with the following code:

    package example;
    import static com.faunadb.client.query.Language.*;
    import static com.faunadb.client.query.Language.TimeUnit.*;
    import static com.faunadb.client.types.Codec.*;
    import static com.faunadb.client.types.Value.NullV.NULL;
    import com.faunadb.client.FaunaClient;
    import com.faunadb.client.types.*;
    import com.faunadb.client.types.Value.*;
    * The class for our example app code.
    public class App {
        * The example.
        public static void main(String[] args) throws Exception {
            String secret   = System.getenv("FAUNADB_SECRET");
            String endpoint = System.getenv("FAUNADB_ENDPOINT");
            if (secret == null || secret == "") {
                    "The FAUNADB_SECRET environment variable is not set, exiting."
            if (endpoint == null || endpoint == "") {
                endpoint = "";
            FaunaClient client = FaunaClient.builder()
                            "data", Obj(
                                "first", Value("Linus"),
                                "last", Value("Torvalds"),
                                "age", Value(52)
  9. Compile the application

    mvn clean package

    Note that the first compilation might take a while as dependencies are downloaded. Subsequent compilations should be notably faster.

  10. Run the application

    java -jar target/example.jar

    You should see results similar to this:

    {ref: ref(id = "324883734738240000", collection = ref(id = "People", collection = ref(id = "collections"))), ts: 1646092123640000, data: {first: "Linus", last: "Torvalds", age: 52}}

    If you get an error, check to make sure that the secret for your access key is correct.

Next steps

Now that your development environment is set up, you’re ready to start developing more complex applications. The following resources can help.

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email

Thank you for your feedback!