Question

I have a multi-module maven project. Building the POM on the parent should build all of the child modules and finally build a child module which prepares an executable jar. This final module includes an ant script which runs an executable and will not work when run from the parent but will work when the POM for the child is run in isolation. I assume the problem is a maven classpath one.

The antrun section of the POM is:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <!-- Clean execution is here-->

                <execution>
                    <id>compile</id>
                    <phase>package</phase>
                    <configuration>
                        <target>
                            <!-- I have tried commenting out the following 4 lines but this does not work.-->
                            <property name="compile_classpath" refid="maven.compile.classpath" />
                            <property name="runtime_classpath" refid="maven.runtime.classpath" />
                            <property name="test_classpath" refid="maven.test.classpath" />
                            <property name="plugin_classpath" refid="maven.plugin.classpath" />
                            <property name="buildConfig" value="${buildConfig}" />
                            <property name="buildversion" value="${currentVersion}" />
                            <ant antfile="${basedir}/ANT FILE NAME.xml">
                                <target name="all" />
                            </ant>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

The Ant script contains the lines:

<target name="generate.scripts" depends="" description="generate scripts">
    <mkdir dir="${distdir.product}" />
    <mkdir dir="${distdir.product}/bin" />
    <exec executable="bin/start.bat" dir="." failonerror="true">
        <arg line="-server -createscript ${distdir.product}/bin/startserver.bat" />
    </exec>

And fails with :

Cannot run program "bin\start.bat" (in directory "CORRECT_DIRECTORY"): CreateProcess error=2, The system cannot find the file specified

Any ideas?

Was it helpful?

Solution

Try with the following exec version:

<exec executable="cmd" dir="${basedir}/bin" failonerror="true">
    <arg value="/c" />
    <arg value="start.bat" />
    <arg value="-server" />
    <arg value="-createscript" />
    <arg value="${distdir.product}/bin/startserver.bat" />
</exec>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top