If you have a proper Maven project already set up, then just adding the dependency for the themoviedbapi
Maven package should be enough. It will cause Maven to bring in all of the dependencies needed by the library, including the slf4j and log4j libraries.
But you say you "downloaded the jar file", which suggests you aren't using Maven at all, or at least not entirely. If you don't use Maven, you're going to need to manually download a few different jar files that is API library requires. Better to get set up properly with Maven.
As a comment to the first answer, you suggest that you are using Maven, so I'm not sure what's going on. I just set up the most basic of Maven projects, and I was able to run the sample code just fine. It complains about not having a proper API key, which means it is working.
You need just two things to build this with Maven...a main Java class file and a pom.xml
file. Create a directory for your project, then put this pom.xml
file in it:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>info.movito</groupId>
<artifactId>themoviedbapi</artifactId>
<version>1.10</version>
</dependency>
</dependencies>
</project>
Then save this file at the location indicated by creating the directory hierarchy shown here:
src/main/java/com/example/demo/MainApplication.java
package com.example.demo;
import info.movito.themoviedbapi.TmdbApi;
import info.movito.themoviedbapi.TmdbMovies;
import info.movito.themoviedbapi.model.MovieDb;
public class DemoApplication {
public static void main(String[] args) {
TmdbMovies movies = new TmdbApi("APIKEY").getMovies();
MovieDb movie = movies.getMovie(5353, "en");
System.out.println(movie);
}
}
Then, if you're using an IDE, load the pom.xml
file into it as a project.
If you have Maven configured to work at a command prompt, just cd
into your project directory and type:
mvn package
The project should build. Then you can run it with:
java -jar target/demo-0.0.1-SNAPSHOT.jar com.example.demo.MainApplication
Here's what I got when I ran the code:
Exception in thread "main" ResponseStatus{code=7, message=Invalid API key: You must be granted a valid key.}
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:78)
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:45)
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:40)
at info.movito.themoviedbapi.TmdbConfig.getConfig(TmdbConfig.java:18)
at info.movito.themoviedbapi.TmdbApi.<init>(TmdbApi.java:54)
at info.movito.themoviedbapi.TmdbApi.<init>(TmdbApi.java:44)
at com.example.demo.DemoApplication.main(DemoApplication.java:10)
This is actually a good thing. This means the demo code is running, but needs to be configured with an API key to run properly.