github/gitignore · Java.gitignore

Java .gitignore Template Explained

Why Java.gitignore ignores .class files, package archives (jar, war) and JVM crash logs, and the ordering issue when combining it with build-tool templates.

Open in generator Open with Maven, Gradle, JetBrains, macOS

Java.gitignore is a short template of about 13 lines that deals only with compilation output and files left by the JVM. It does not include Maven's target/ or Gradle's build/, so real projects usually combine it with the Maven or Gradle template and an IDE template.

The rule to watch most closely is *.jar. It is meant to keep distribution archives out of the repository, but it also ignores build-tool wrapper jars, so you need to pay attention to the order of the combination.

Rules explained

PatternWhat it ignores and why
*.classCompilation outputBytecode that javac produces from source. It can be rebuilt at any time from the source, and its contents vary by compiler version.
*.jar*.war*.nar*.ear*.zip*.tar.gz*.rarPackage archivesDistribution files and compressed archives produced by builds. The goal is to fetch dependency jars from a repository such as Maven Central instead of the old practice of putting them directly in the repository.
hs_err_pid*replay_pid*JVM crash logshs_err_pid<number>.log, which the JVM leaves in the working directory when it crashes, and replay_pid files for reproducing JIT compiler issues. They are one-off debugging files.
*.logLogsApplication run logs. Committing log files creates changes on every run and can leak operational information.
*.ctxt.mtj.tmp/BlueJ and J2MEContext files from the educational IDE BlueJ and the temporary folder of Mobile Tools for Java (J2ME). They have no effect if you do not use those tools.

Practical notes

Original template

Java.gitignore13 rules
# Compiled class file*.class# Log file*.log# BlueJ files*.ctxt# Mobile Tools for Java (J2ME).mtj.tmp/# Package Files #*.jar*.war*.nar*.ear*.zip*.tar.gz*.rar# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xmlhs_err_pid*replay_pid*

Templates from github/gitignore/Java.gitignore @356fd7b (2026-09-11) · CC0-1.0

Often used together

More template explanations