jmcg
jmcg

Reputation: 1567

Maven - How to place a single resource file on a separate location from the other resource files?

So I created a windows batch file that i would like to include on my build using Maven. I placed it in the src/main/resources folder. When I do a mvn clean install, my resources end up on a folder named conf in the same directory as the jar file.

Basically I would like to have the windows batch file on the same directory as my jar, with my other resource files in the conf folder.

+ conf/
    ... my resource files
- myjar.jar 
- myBatchFile.bat

here is a snippet of the maven plugin that does it:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>install</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/target/conf</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <includes>
                            <include>**/*.properties</include>
                            <include>**/*.csv</include>

                            <!-- include my batch file -->
                            <include>**/*.bat</include>

                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

AS EXPECTED, my batch file went inside the conf folder.

Question: Is there a way to have the batch file sit beside my jar, while all other resource files inside conf?

Upvotes: 0

Views: 947

Answers (1)

A_Di-Matteo
A_Di-Matteo

Reputation: 27862

Try to change your configuration to the following:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>install</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/target/conf</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <includes>
                            <include>**/*.properties</include>
                            <include>**/*.csv</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
        <execution>
            <id>copy-batch</id>
            <phase>install</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/target</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <includes>
                            <!-- include my batch file -->
                            <include>**/*.bat</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>            
    </executions>
</plugin>

We are basically adding a further execution of the same plugin for the same phase which will take care of specific batch file and its copy while removing the batch inclusion from the previous execution.

Upvotes: 2

Related Questions