Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set directory in Maven Antrun Plugin

I've downloaded jquery-ui to my webapp which has a build.xml for compressing and minifying. Now I would like to run this build.xml from within my pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <id>compile</id>
        <phase>compile</phase>
        <configuration>
          <target>
            <ant antfile="src/main/webapp/resources/js/jquery-ui/build/build.xml" />
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

But now the behavior for this buildfile is wrong. It creates a dist folder on the wrong place. Here's thebuild.xml` from jquery-ui: https://github.com/jquery/jquery-ui/blob/master/build/build.xml

It creates the dist folder on the same place where pom.xml is (same place i run mvn clean package) and it should create it in src/main/webapp/resources/js/jquery-ui/build

Is it possible to run build.xml from a specified directory (working directory)? Can't access the documentation for the Ant task: http://ant.apache.org/manual/CoreTasks/ant.html

EDIT: pom.xml

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example.myproject</groupId>
  <artifactId>myproject</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>myproject</name>

  <dependencies>
    <!-- ... -->
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <!-- ... -->
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <warName>myproject</warName>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>install</id>
            <phase>install</phase>
            <goals>
              <goal>sources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>compile</phase>
            <configuration>
              <executable>make</executable>
              <workingDirectory>src/main/webapp/resources/js/jquery</workingDirectory>
            </configuration>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>compile</phase>
            <configuration>
              <target>
                <ant antfile="build.xml" dir="src/main/webapp/resources/js/jquery-ui/build" />
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

On running mvn clean package I'm getting the following errors in minify target of jquery-ui's build.xml:

[apply] build/minify-js.sh: Line 3: /home/danny/myproject/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js: File or directory not found

The correct path should be ${basedir}/src/main/webapp/resources/js/jquery-ui/build/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js instead of the above mentioned...

like image 205
dtrunk Avatar asked Mar 19 '12 12:03

dtrunk


People also ask

What Maven Antrun plugin does?

The maven-antrun-plugin has only one goal, run . This allows Maven to run Ant tasks. To do so, there must be an existing project and maven-antrun-plugin must have its <target> tag configured (although it would still execute without the <target> tag, it would not do anything).

What is Maven Antrun?

This plugin provides the ability to run Ant tasks from within Maven. You can even embed your Ant scripts in the POM! It is not the intention of this plugin to provide a means of polluting the POM, so it's encouraged to move all your Ant tasks to a build.

How do I run an Ant script from Maven?

Action. Configure the run goal form the Maven AntRun plugin. Define any properties you wish to pass to the external Ant build, and then call the external Ant build with the ant task, specifying the antfile and target you wish to execute. To execute this external Ant build, run mvn package.

What are the names of build files in Ant and Maven respectively?

Done. Maven just created 3 Ant files – build. xml, maven-build. xml and maven-build.


1 Answers

According to http://ant.apache.org/manual/Tasks/ant.html, you can use the dir attribute:

<mkdir dir="${project.build.directory}/jquery-ui" />
<ant antfile="src/main/webapp/resources/js/jquery-ui/build/build.xml" dir="${project.build.directory}/jquery-ui" />

On the other hand, are you really sure you want to create the build directory underneath your src directory? Shouldn't this go into target rather?

like image 51
nwinkler Avatar answered Jan 02 '23 08:01

nwinkler