在Maven Antrun插件中设置目录

时间:2012-03-19 12:56:55

标签: maven maven-antrun-plugin

我已经将jquery-ui下载到我的webapp,其中有build.xml用于压缩和缩小。 现在,我想在build.xml

中运行此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>

但现在来自jquery-ui的s buildfile is wrong. It creates a dist folder on the wrong place. Here's the build.xml`的行为:https://github.com/jquery/jquery-ui/blob/master/build/build.xml

它在pom.xml所在的同一个地方(我运行mvn clean package的同一个地方)创建了dist文件夹,它应该在src/main/webapp/resources/js/jquery-ui/build中创建它

是否可以从指定目录(工作目录)运行build.xml? 无法访问Ant任务的文档:http://ant.apache.org/manual/CoreTasks/ant.html

编辑: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>

在运行mvn clean package时,我在jquery-ui的build.xml的minify目标中遇到以下错误:

[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

正确的路径应该是$ {basedir} /src/main/webapp/resources/js/jquery-ui/build/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js上面提到的......

2 个答案:

答案 0 :(得分:5)

根据http://ant.apache.org/manual/Tasks/ant.html,您可以使用dir属性:

<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" />

另一方面,您确定要在build目录下创建src目录吗?这不应该进入target吗?

答案 1 :(得分:0)

我建议使用maven插件而不是Ant调用。基于docs maven-minify-plugin来做你需要的。该插件可以在Maven Central中找到。此外,您会发现maven-plugin-documention如何使用maven-plugin。