.gitignore for Java
13 ignore rules for Java, ready to copy into your repository.
The Java programming language
The complete .gitignore for Java
# Generated by LFGitignore - https://lfgitignore.com
# Created: 2025-08-25 07:46:19 UTC
# Technologies: Java
### Java ###
# Java compiled class file
*.class
# Java archive
*.jar
# Log file
*.log
*.ctxt
# Web application archive
*.war
.mtj.tmp/
# Native archive
*.nar
# Enterprise archive
*.ear
# ZIP archive
*.zip
# Gzipped tar archive
*.tar.gz
# RAR archive
*.rar
# Java crash log
hs_err_pid*
# Java replay file
replay_pid*
What these Java rules actually ignore
Every pattern below, and why it belongs in your .gitignore.
Compiled class file
| Pattern | What it ignores |
|---|---|
*.class |
Java compiled class file |
Package Files #
| Pattern | What it ignores |
|---|---|
*.jar |
Java archive |
*.war |
Web application archive |
*.nar |
Native archive |
*.ear |
Enterprise archive |
*.zip |
ZIP archive |
*.tar.gz |
Gzipped tar archive |
*.rar |
RAR archive |
hs_err_pid* |
Java crash log |
replay_pid* |
Java replay file |
Log file
| Pattern | What it ignores |
|---|---|
*.log |
Log file |
BlueJ files
| Pattern | What it ignores |
|---|---|
*.ctxt |
BlueJ files |
Mobile Tools for Java (J2ME)
| Pattern | What it ignores |
|---|---|
.mtj.tmp/ |
Mobile Tools for Java (J2ME) |
How to use this .gitignore for Java
- Copy the Java rules above, or download the file directly.
- Create a file named .gitignore at the root of your Git repository and paste the rules into it.
- If some of those files are already tracked, run git rm -r --cached . then commit again — Git only applies ignore rules to untracked files.
- Commit the .gitignore so everyone on the team shares the same rules.