Question

I use maven-antrun-plugin for init config files for my project. But i need to init config files just once, when i first start to init my dev environment, not each time i launch jetty:run.

If I attach phase to process-resouces for example, each time I launch jetty, my config files are reseted.

So i configured antrun like this :

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
        <goals>
            <goal>run</goal>
        </goals>
        <configuration>
            <target name="init_config_files">
                <!-- init files -->
            </target>
        </configuration>
        </execution>
    </executions>
</plugin>

If I launch mvn antrun:run, it just return me this error : "[INFO] No ant target defined - SKIPPED". And it is the same thing, if I specify target : "mvn antrun:run -Dtarget=init_config_files".

Was it helpful?

Solution

Try this:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>default-cli</id>
                    <configuration>
                        <target>
                            <property name="compile_classpath" refid="maven.compile.classpath" />
                            <echo message="compile classpath: ${compile_classpath}" />
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

and run this:

 mvn antrun:run

OTHER TIPS

Best solution I have found so far:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>go-live</id>
                    <configuration>
                        <target>
                            <!-- go live! -->
                            <exec executable="${basedir}/deploy2server.sh" failonerror="true" dir="${basedir}">
                                <arg value="deploy" />
                                <arg value="${deploy.to.server}" />
                                <arg value="${jetty.port.live}" />
                            </exec>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

and run this:

 mvn antrun:run@go-live

This solution avoids the target being run by accident, ie. it does not run just by typing "mvn antrun:run" and it also does not run during regular maven runs. I'm using this for qa auto-deployment in my jenkins instance after all modules incl integration done against the final distribution package have been successfully executed.

I just ran into the same problem and finally figured it out: If you want to run the ant tasks only once, you can set the plugin up like this:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <configuration>
        <target name="init_config_files">
            <!-- init files -->
        </target>
    </configuration>
</plugin>

and use mvn antrun:run to execute it. That way, the ant stuff is not bound to any phase.

If you need to run some part of build on special conditions (e.g. once), you can put those parts into a Maven profile and then invoke Maven specifying profile name, e.g. mvn -p init_config_files package

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top