7

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...

Tunaki
  • 132,869
  • 46
  • 340
  • 423
dtrunk
  • 4,685
  • 17
  • 65
  • 109

2 Answers2

7

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?

nwinkler
  • 52,665
  • 21
  • 154
  • 168
  • Oh, right... How the ant task should look like then? See edit above for my pom.xml – dtrunk Mar 19 '12 at 13:44
  • Did you try to add the `dir` attribute as shown in my example? – nwinkler Mar 19 '12 at 13:46
  • You can substitute `target` with `${project.build.directory}`. I would append something that tells you the purpose of the directory, e.g. `jquery-ui`. – nwinkler Mar 19 '12 at 13:52
  • `An Ant BuildException has occured: Basedir /home/danny/myproject/target/jquery-ui does not exist` I need to have a resources folder beside WEB-INF to have the correct folder structure to access the resources. – dtrunk Mar 19 '12 at 15:38
  • The error is caused by the `target/jquery-ui` directory not being there. I have changed the above example to create the directory first. Ant's `mkdir` task can be used for that. – nwinkler Mar 19 '12 at 15:41
  • I guess I need to specify another lifecycle phase for those plugins, because there are no files in target/myproject-1.0-SNAPSHOT. When files are copied in there I could run the build machanism for jquery+jquery-ui to only build it there... I'm a little bit confused now... – dtrunk Mar 19 '12 at 15:53
  • You could also build it there, yes, absolutely. – nwinkler Mar 19 '12 at 16:00
0

I would recommend to use the maven plugin instead of Ant calls. Based on the docs maven-minify-plugin to do what you need. The plugin can be found in Maven Central. And furthermore you will find the maven-plugin-documention how to use the maven-plugin.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • But it would be more dynamically to use the provided build.xml from jquery ui. if something changes in folder structure/files will be added and so on i always have to update my code as well... – dtrunk Mar 19 '12 at 18:59