Was this article helpful?
Thanks for your feedback
This guide will help you get started with Contentstack Java SDK to build apps powered by Contentstack.
To get started with the Java SDK, you will need the following:
To install the Java SDK, choose either of the following methods (Maven or Gradle).
Add the following dependency code snippets into your project:
Maven
<dependency> <groupid>com.contentstack.sdk</groupid> <artifactid>java</artifactid> <version>{latest}</version> </dependency>
Maven users need to add the above code in your pom.xml file under the <dependencies> section.
Gradle
compile 'com.contentstack.sdk:java:{latest}'
Gradle users need to add the above dependency code into your build.gradle file.
You can download the latest dependency version here.
To initialize the Live Preview feature, you need to configure certain settings:
Config config = new Config(); config.enableLivePreview(true).setLivePreviewHost("api.contentstack.io").setManagementToken("management_token");
Note: By default, the setLivePreviewHost() method points to the North America endpoint. If your website is hosted on the European data center, then pass the European endpoint against this method.
Since the Live Preview Utils SDK is responsible for communication, you need to initialize it within your stack.
Use the following command to initialize the stack:
Stack stack = Contentstack.stack("APIKey", "deliveryToken", "environment", config);
Use the following code to create an interceptor:
@Component public class ServiceInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { System.out.println("Pre Handle getQueryString: " + request.getQueryString()); stack.livePreviewQuery(request.getQueryString()) return true; } }
To install and initialize the Live Preview Utils SDK, you can refer to our SSR Live Preview Setup documentation.
Contentstack SDKs let you interact with the Content Delivery APIs and retrieve content from Contentstack. They are read-only in nature. The SDKs fetch and deliver content from the nearest server via Fastly, our powerful and robust CDN.
To get an entry, you need to specify the content type UID and the UID of the entry.
Entry entry = stack.contentType("contentType").entry(); entry.fetch(new EntryResultCallBack() { });
Was this article helpful?
Thanks for your feedback