Showing posts with label antrun. Show all posts
Showing posts with label antrun. Show all posts

Wednesday, April 13, 2016

Maven maven-antrun-plugin run executions in various phases

Maven maven-antrun-plugin run executions in various phases.
This is an example of that:


<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>1</id>
            <phase>generate-test-resources</phase>
            <configuration>
                <target>
                    <echo message="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"/>
                    <echo message="run - generate-test-resources"/>
                    <echo message="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
        <execution>
            <id>2</id>
            <phase>generate-resources</phase>
            <configuration>
                <target>
                    <echo message="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"/>
                    <echo message="run - generate-resources"/>
                    <echo message="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
        <execution>
            <id>443-4</id>
            <phase>process-test-classes</phase>
            <configuration>
                <target>
                    <echo message="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"/>
                    <echo message="process-test-classes"/>
                    <echo message="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"/>
                    <fail/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
        <execution>
            <id>3</id>
            <phase>test</phase>
            <configuration>
                <target>
                    <echo message="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"/>
                    <echo message="DOES NOT RUN ! test"/>
                    <echo message="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Monday, March 14, 2016

Maven antrun java.io.IOException: "Cannot run program" because "The filename or extension is too long"

There is an issue on where the command that maven antrun fails to run a java because the command line is too long.
In my case the classpath was way too long.

To fix it the classpath needs to be written to a manifest in a jar file and that needs to be used by java to get the classpath.

Here is an example of how to do it:


<manifestclasspath property="manifest.classpath"
                   jarfile="target/classpathSupplier.jar"
                   maxParentLevels="99">
    <classpath refid="maven.compile.classpath" />
</manifestclasspath>
<!-- Create pathing Jar --><jar destfile="target/classpathSupplier.jar">
    <manifest>
        <attribute name="Class-Path" value="${manifest.classpath}"/>
    </manifest>
</jar>
<java classname="org.me.ClassToRun" fork="yes" failonerror="true">
    <arg value="-someArg" />
    <!--<jvmarg value="-Xdebug"/>-->
    <!--<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>-->
    <classpath>
        <pathelement location="target/classpathSupplier.jar"/>
    </classpath>
</java>

Monday, February 22, 2016

maven run ant command only

Here is how to run only the ant command in maven:

mvn antrun:run compile

Assuming the pom.xml is like this:

<profiles>
  <profile>
    <id>x86-windows</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    <build>
      <plugins>

        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <executions>
            <execution>
              <id>compile</id>
              <phase>compile</phase>
              <goals>
                <goal>run</goal>
              </goals>
              <configuration>
                <tasks>
                  <echo>It worked! only running this part!</echo>