Skip to content

1. How to Use JPlag

tsaglam edited this page Feb 21, 2024 · 24 revisions

JPlag can be used via the Command Line Interface (CLI) or programmatically via the Java API.

Using JPlag via the CLI

JPlag can be used via the Command Line Interface by executing the JAR file.

Example: java -jar jplag.jar path/to/the/submissions

The language can either be set with the -l parameter or as a subcommand. If both a subcommand and the -l option are specified, the subcommand will take priority. When using the subcommand language specific arguments can be set. A list of language specific options can be obtained by requesting the help page of a subcommand (e.g. "jplag java -h").

The following arguments can be used to control JPlag:

Parameter descriptions: 
                        Root-directory with submissions to check for plagiarism.
      -bc, --bc, --base-code=<baseCode>
                        Path to the base code directory (common framework used in all submissions).
  -l, --language=<language>
                        Select the language of the submissions (default: java). See subcommands below.
  -M, --mode=<{RUN, VIEW, RUN_AND_VIEW}>
                        The mode of JPlag: either only run analysis, only open the viewer, or do both (default: null)
  -n, --shown-comparisons=<shownComparisons>
                        The maximum number of comparisons that will be shown in the generated report, if set to -1 all comparisons will be shown (default: 500)
      -new, --new=<newDirectories>[,<newDirectories>...]
                        Root-directories with submissions to check for plagiarism (same as root).
      --normalize       Activate the normalization of tokens. Supported for languages: Java, C++.
      -old, --old=<oldDirectories>[,<oldDirectories>...]
                        Root-directories with prior submissions to compare against.
  -r, --result-file=<resultFile>
                        Name of the file in which the comparison results will be stored (default: results). Missing .zip endings will be automatically added.
  -t, --min-tokens=<minTokenMatch>
                        Tunes the comparison sensitivity by adjusting the minimum token required to be counted as a matching section. A smaller value increases the sensitivity but might lead to more

      --csv-export      Export pairwise similarity values as a CSV file.
  -d, --debug           Store on-parsable files in error folder.
  -m, --similarity-threshold=<similarityThreshold>
                        Comparison similarity threshold [0.0-1.0]: All comparisons above this threshold will be saved (default: 0.0).
  -p, --suffixes=<suffixes>[,<suffixes>...]
                        comma-separated list of all filename suffixes that are included.
  -P, --port=<port>     The port used for the internal report viewer (default: 1996).
  -s, --subdirectory=<subdirectory>
                        Look in directories <root-dir>/*/<dir> for programs.
  -x, --exclusion-file=<exclusionFileName>
                        All files named in this file will be ignored in the comparison (line-separated list).

      --cluster-alg, --cluster-algorithm=<{AGGLOMERATIVE, SPECTRAL}>
                        Specifies the clustering algorithm (default: spectral).
      --cluster-metric=<{AVG, MIN, MAX, INTERSECTION}>
                        The similarity metric used for clustering (default: average similarity).
      --cluster-skip    Skips the cluster calculation.

Subsequence Match Merging
                        Maximal gap between neighboring matches to be merged (between 1 and minTokenMatch, default: 6).
      --match-merging   Enables merging of neighboring matches to counteract obfuscation attempts.
                        Minimal length of neighboring matches to be merged (between 1 and minTokenMatch, default: 2).

Subcommands (supported languages):

Note that the legacy CLI is varying slightly.

Using JPlag programmatically

The new API makes it easy to integrate JPlag's plagiarism detection into external Java projects.


JavaLanguage language = new JavaLanguage();
language.getOptions(); //Use this to set language specific options, same as language specific arguments above.
Set<File> submissionDirectories = Set.of(new File("/path/to/rootDir"));
File baseCode = new File("/path/to/baseCode");
JPlagOptions options = new JPlagOptions(language, submissionDirectories, Set.of()).withBaseCodeSubmissionDirectory(baseCode);

try {
    JPlagResult result =;
    // Optional
    ReportObjectFactory reportObjectFactory = new ReportObjectFactory(new File("/path/to/output"));
    reportObjectFactory.createAndSaveReport(result, "/path/to/output");
} catch (ExitException e) {
    // error handling here

Report File Generation

After a JPlag run a zipped result report is automatically created. The target location of the report can be specified with the -r flag.

If the -r is not specified, the location defaults Specifying the -r flag with a path /path/to/desiredFolder results in the report being created as /path/to/

Unless there is an error during the zipping process, the report will always be zipped. If the zipping process fails, the report will be available as unzipped under the specified location.

Viewing Reports

The newest version of the report viewer is always accessible at Simply drop your folder on the page to start inspecting the results of your JPlag run. Your submissions will neither be uploaded to a server nor stored permanently. They are saved in the application as long as you view them. Once you refresh the page, all information will be erased.

Basic Concepts

This section explains some fundamental concepts about JPlag that make it easier to understand and use.

  • Root directory: This is the directory in which JPlag will scan for submissions.
  • Submissions: Submissions contain the source code that JPlag will parse and compare. They have to be direct children of the root directory and can either be single files or directories.

Single-file submissions

├── ...

Directory submissions

JPlag will read submission directories recursively, so they can contain multiple (nested) source code files.

├── Submission-1
│   ├──
│   └── util
│       └──
├── ...
└── Submission-n
    └── util

If you want JPlag to scan only one specific subdirectory of the submissions for source code files (e.g. src), can configure that with the argument -S:

├── Submission-1
│   ├── src                 
│   │   ├──       # Included
│   │   └── util            
│   │       └──  # Included
│   ├── lib                 
│   │   └──    # Ignored
│   └──          # Ignored
└── ...

Base Code

The base code is a special kind of submission. It is the template that all other submissions are based on. JPlag will ignore all matches between two submissions, where the matches are also part of the base code. Like any other submission, the base code has to be a single file or directory in the root directory.

├── BaseCode
│   └──
├── Submission-1
│   └──
├── ...
└── Submission-n

In this example, students have to solve a given problem by implementing the run method in the template below. Because they are not supposed to modify the main function, it will be identical for each student.

// BaseCode/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution(); ;
    public void run() {
        // TODO: Implement your solution here.

To prevent JPlag from detecting similarities in the main function (and other parts of the template), we can instruct JPlag to ignore matches with the given base code by providing the --bc=<base-code-name> option. The <base-code-name> in the example above is BaseCode.

Multiple Root Directories

  • You can run JPlag with multiple root directories, JPlag compares submissions from all of them
  • JPlag distinguishes between old and new root directories ** Submissions in new root directories are checked amongst themselves and against submissions from other root directories ** Submissions in old root directories are only checked against submissions from other new root directories
  • You need at least one new root directory to run JPlag

This allows you to check submissions against those of previous years:

└── ...
└── ...
└── ...


The following diagram shows all the relations between root directories, submissions, and files:

    direction LR

    Input -->"1..*" RootDirectory : consists of
    RootDirectory <|-- NewDirectory: is a
    RootDirectory <|-- OldDirectory : is a
    RootDirectory --> "1..*" Submission : contains
    Directory --> "1..*" File : contains
    Submission <|-- File : is a
    Submission <|-- Directory : is a