Java Quickstart Guide
This guide will walk you through installing the official Java SDK and running your first scan. In just a few minutes, you’ll be able to check content for plagiarism, AI-generated text, moderation and more directly from your Java application.
🔑 Before you begin
In order to start integrating Copyleaks API, you'll need an account and an API key:
- Don't have an account? Sign up for free
- You can find your API key on the API Dashboard
🚀 Get Started
Section titled “🚀 Get Started”-
Installation
The SDK requires Java 11 or higher. Add the official
copyleaks-java-sdkdependency to your project’spom.xmlfile.pom.xml <dependency><groupId>com.copyleaks.sdk</groupId><artifactId>copyleaks-java-sdk</artifactId><version>4.3.0</version></dependency> -
Quick Example: Scan Text
ScanExample.java import classes.Copyleaks;import models.response.CopyleaksAuthToken;import models.submissions.CopyleaksFileSubmissionModel;import models.submissions.properties.SubmissionProperties;import models.submissions.properties.SubmissionWebhooks;import java.nio.charset.StandardCharsets;import java.util.Base64;import java.util.Random;public class ScanExample {// --- Your Credentials ---private static final String EMAIL_ADDRESS = "YOUR_EMAIL_ADDRESS";private static final String KEY = "YOUR_API_KEY";private static final String WEBHOOK_URL = "[https://your-server.com/webhook/](https://your-server.com/webhook/){STATUS}";// --------------------public static void main(String[] args) {CopyleaksAuthToken token;try {// Log in to the Copyleaks APISystem.out.println("Authenticating...");token = Copyleaks.login(EMAIL_ADDRESS, KEY);System.out.println("✅ Logged in successfully!");// Prepare your content for scanningSystem.out.println("Submitting text for scanning...");String textToScan = "Hello world, this is a test.";String base64Content = Base64.getEncoder().encodeToString(textToScan.getBytes(StandardCharsets.UTF_8));String filename = "test.txt";String scanId = Integer.toString(new Random().nextInt(100000));// Configure the scanSubmissionWebhooks webhooks = new SubmissionWebhooks(WEBHOOK_URL);SubmissionProperties submissionProperties = new SubmissionProperties(webhooks);submissionProperties.setSandbox(true); // Turn on sandbox mode for testingCopyleaksFileSubmissionModel submissionModel = new CopyleaksFileSubmissionModel(base64Content, filename, submissionProperties);// Submit the scan to CopyleaksCopyleaks.submitFile(token, scanId, submissionModel);System.out.println("🚀 Scan submitted successfully! Scan ID: " + scanId);System.out.println("You will be notified via your webhook when the scan is complete.");} catch (Exception e) {System.out.println("🛑 An error occurred:");e.printStackTrace();}}} -
Understanding the Code
The example code performs four main actions to submit a scan:
- Login: It authenticates with your email and API key to get a secure
CopyleaksAuthTokenobject, which is required for all subsequent requests. - Prepare Content: It takes a simple string of text and encodes it into Base64 format.
- Configure Scan: It creates a
SubmissionPropertiesobject containingSubmissionWebhooksto define the scan’s behavior. We enablesandboxmode for safe testing and provide the webhook URL. - Submit for Scanning: It creates a
CopyleaksFileSubmissionModelwith the content and properties, then sends it to the Copyleaks API. The process is asynchronous; Copyleaks will notify your webhook URL once the scan is complete.
- Login: It authenticates with your email and API key to get a secure
🗺️ Next Steps
Section titled “🗺️ Next Steps”Now that you’ve submitted your first scan, here are some recommended steps: