0

I am currently developing an maven based application. I want to make a bat file to run final jar. I've wrote bat file with call to java -jar... and put it into src/main/resources/runners folder. I also do not want to add this file to jar, so i excluded it from resources plugin. The problem is that bat is not copied. I've copypasted maven-resources-plugin configuration from their site, it does not work. However, i want copy bat only while calling jar:jar. Application is hosted here, so you can see details there. I tried to bind copying as such:

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <!-- here the phase you need -->
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/runners</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Also tried <phase>package</phase> and <goal>jar</goal> (and <goal>jar:jar</goal>). No effect.

By the way: where can i read about maven phases and goals more detailed, then in official documentation (understood nothing from it)?

tshepang
  • 12,111
  • 21
  • 91
  • 136
madhead
  • 31,729
  • 16
  • 153
  • 201

1 Answers1

1

You could use the pre-integration-test phase, which will only be run if your jar was succesfully created by the build. You will then need to run a build through integration-test, verify, install, or deploy to ensure that the copy-resources is run.

<plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
            <execution>
                <id>copy-builders</id>
                <!-- here the phase you need -->
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                    <resources>
                        <resource>
                            <directory>src/main/runners</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>

You can read more about the lifecycle at: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html.

Ryan Gross
  • 6,423
  • 2
  • 32
  • 44
  • Just tried it, no effect. Jar was created, resource filtered, but bat was not copyed to /target... – madhead Nov 26 '11 at 18:50
  • Hmm, everything works file, when i call mvn clean package but not when i call mvn clean compile jar:jar – madhead Nov 26 '11 at 18:56
  • When you only run jar:jar, you run that goal alone. This is because you specified the goal directly (`jar`:jar). If reference one of the lifecycle phases (package or install) all lifecycle phases up to and including that one will be run. – Ryan Gross Nov 26 '11 at 22:32
  • I've untersood that, but thanks for your response. Now i have anoter troubles with maven: http://stackoverflow.com/q/8281941/750510 – madhead Nov 26 '11 at 22:55