9

Can you show me example of .gitignore file for java, that consider a lot of different files that are not included(jar, war, classpath, files that IDEA and other IDE generates and so on and on). I mean really big .gitignore.

What I currently have is

**/target/
/target/
*/target/*
.classpath
.project
.settings

# Package Files #
*.jar
*.war
*.ear

*.iml
*.idea
4
  • could anybody share file that he uses himself? Apr 2, 2015 at 5:19
  • What you are asking is not simply about "Java". It is highly related to the IDE, build tools, setting of tools etc that you are using. Apr 2, 2015 at 8:59
  • Just one thing to comment: seems you are using Maven (from the target/). Adding *.jar, *.war, *.ear are superfluous given that in a proper Maven project, such packaged output should be put under target directory. You do not need to exclude them again. Apr 2, 2015 at 9:06
  • gitignore.io/api/maven,java is what you want. If not, go to gitignore.io and select the IDE/Language combination you need.
    – eckes
    Apr 2, 2015 at 10:18

3 Answers 3

23

This .gitignore has other Java-related temp files added -

https://gist.github.com/dedunumax/54e82214715e35439227

##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*

##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

##############################
## Gradle
##############################
bin/
build/
.gradle
.gradletasknamecache
gradle-app.setting
!gradle-wrapper.jar

##############################
## IntelliJ
##############################
out/
.idea/
.idea_modules/
*.iml
*.ipr
*.iws

##############################
## Eclipse
##############################
.settings/
bin/
tmp/
.metadata
.classpath
.project
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
.factorypath

##############################
## NetBeans
##############################
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

##############################
## Visual Studio Code
##############################
.vscode/
.code-workspace

##############################
## OS X
##############################
.DS_Store
9

check https://www.gitignore.io/.

If you want .gitignore file, pick up some from https://www.gitignore.io/api/java%2Cintellij

1
  • Thanks for the link. Very helpful! Sep 28, 2017 at 8:42
5

You can get sample java gitignore files at https://github.com/github/gitignore/blob/master/Java.gitignore

Based on the comments , here is a gist of the sample gitignore class

*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
2
  • 1
    no, that is not what I meant. That file includes only*.jar *.war *.ear and that is pretty is. What about files that are generated by IDEA for example? Apr 2, 2015 at 5:10
  • You may find the following link useful Jetbrains Gitignore
    – rahduro
    Mar 6, 2016 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.