Java .gitignore Template

The full, current Java .gitignore template — copy it as-is, or head to the .gitignore Generator to merge it with other stacks into one file.

Template

# 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.xml
hs_err_pid*
replay_pid*

What each entry does

Why every line in this template is excluded, not just what it matches.

Entry Why it's excluded
*.class Compiled Java bytecode — regenerated by the build from the .java source.
*.log Runtime log output — grows unbounded, is different on every machine/run, and has no value in version control.
*.ctxt Files matching *.ctxt — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
.mtj.tmp/ A generated/local directory (.mtj.tmp) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff.
*.jar Files matching *.jar — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.war Files matching *.war — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.nar Files matching *.nar — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.ear Files matching *.ear — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.zip Files matching *.zip — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.tar.gz Files matching *.tar.gz — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
*.rar Files matching *.rar — a generated or machine-specific file type for this stack, safe to regenerate rather than track.
hs_err_pid* Excludes hs_err_pid* — generated or machine-specific for this stack, not something to track in version control.
replay_pid* Excludes replay_pid* — generated or machine-specific for this stack, not something to track in version control.