A POM to create a jar, but exclude the config file

Problem

I want to have a POM that will create a JAR file with all dependencies, but exclude src/main/resources/config.properties.

Solution

  1. Make a folder (not a source folder) in Eclipse called src/main/eclipse.
  2. Put the config file in the new folder.
  3. Add the folder to the class path by going into the Run Configuration.

Adding the folder to src/test/resources does not work unless src/test/resources is not a code folder.

I tried this, but somehow Maven always wants to move that file!

 <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.maven.apache.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>**/*.properties</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>src/main/resources/MANIFEST.MF</manifestFile>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <excludes>
                    <exclude>**/config.properties</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.7.2</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resource-plugin</artifactId>
            <version>2.4.3</version>
        </plugin>
    </plugins>
  </build>

References

No votes yet