Adding the JAR Files to Your Classpath Jackson Maven Dependencies Adding the JAR Files Directly to the Classpath
Last update: 2019-02-02
The Java JSON API called Jackson consists of one core JAR file (project) and two other JAR files that use the core JAR file. The three JAR files (projects) in the Jackson JSON API are:
Jackson Core Jackson Annotations Jackson Databind
These projects use each other in that sequence too. Jackson Annotation uses the Jackson Core features, and the Jackson Databind uses Jackson Annotation.
Jackson also has a few extra projects for parsing other data formats than JSON. For instance, to read and write CBOR you can add the jackson-dataformat-cbor artifact to your classpath too.
In order to “install” Jackson in your Java application you need to add these JAR files to the classpath of your application. There are several ways to do so. I will cover two here.
Adding the JAR Files to Your Classpath
In order to use any of the Jackson projects (JAR files) you must add the corresponding JAR file to the classpath of your application. You can do so in several different ways.
Before you even start adding the Jackson JAR files to your classpath, you need to decide what version of the Jackson JSON API to use. To do so, go to the Jackson website and see what versions are available. If you are not already using a specific version of Jackson in your project, use the latest stable version. Write the version number down. You may need it later.
You can find a list of Jackson releases here:
Jackson Maven Dependencies
If your project uses Maven to build (and resolve + download dependencies), you need to add Jackson as a dependency to your project’s POM file. Here is how Jackson as Maven dependencies look:com.fasterxml.jackson.core jackson-core 2.9.6 com.fasterxml.jackson.core jackson-annotations 2.9.6 com.fasterxml.jackson.core jackson-databind 2.9.6
Note, that both jackson-annotations and jackson-databind have “transitive dependencies” to jackson-core (and jackson-databind to jackson-annotations). This means, that if you plan to use the jackson-databind project, you just need to include that as dependency in your Maven POM file. Then it will transitively include the other two projects as dependencies. Regardless, I like to add my dependencies explicitly so I can see what I am using (but that’s just me).
In order to read and write CBOR encoded data with Jackson you will also need to add the Jackson CBOR Maven dependency:com.fasterxml.jackson.dataformat jackson-dataformat-cbor 2.9.6
In order to read and write MessagePack encoded data with Jackson you will also need to add the Jackson MessagePack Maven dependency:org.msgpack jackson-dataformat-msgpack 0.8.16
In order to read and write YAML encoded data with Jackson you will also need to add the Jackson YAML Maven dependency:com.fasterxml.jackson.dataformat jackson-dataformat-yaml 2.9.0
Adding the JAR Files Directly to the Classpath
Another option is to add the Jackson JAR files directly to the classpath of your application. To do so you must first download the JAR files. You can download the finished JAR files via the central Maven repository. Go to:
Search for the project you want to use (e.g. jackson-core, jackson-annotation or jackson-databind). Once you find the right project, make sure you click the “all versions” link next to the version number in the search result. That will show you a list of the previous versions of that project. Click around until you find a link directly to the JAR file for that project and that version. Then download the JAR file.
Once the JAR files are downloaded, add them to the classpath of your project. You can do so within your IDE, and / or within the scripts (bash or cmd) you use to run your application.
Next: Jackson ObjectMapper