The first thing is using a jar file example projects is astonishing. I would never expect to have example projects within a .jar
file. The intention of a jar files is something different. I would suggest to use something more appropriate like .zip
or .tar.gz
etc. (This can be achieved with the maven-assembly-plugin) This will prevent accidental not intended use.
Apart from the whole problem is based on the definition of resources which are usually copied from src/main/resources
to the target/classes
directory. This is done by the maven-resources-plugin
.
The maven-resources-plugin plugin has some kind of configuration which excludes some files which are usually not copied which contains .gitignore
. So this means just putting a .gitignore
file into src/main/resources
will not produce the expected result nor using <includes>..</includes>
configuration will not help here as well.
This means you need to change the default configuration of maven-resources-plugin via pluginManagement
section like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<addDefaultExcludes>false</addDefaultExcludes>
</configuration>
</plugin>
Than the .gitignore
file will be copied and should be packaged into the resulting jar file (Which I would not recommend to do.)