【问题标题】:Set directory in Maven Antrun Plugin在 Maven Antrun 插件中设置目录
【发布时间】:2012-03-19 12:56:54
【问题描述】:

我已将 jquery-ui 下载到我的 webapp 中,其中有一个 build.xml 用于压缩和缩小。 现在我想在我的pom.xml 中运行这个build.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>

但现在 this buildfile is wrong. It creates a dist folder on the wrong place. Here's thebuild.xml` 的行为来自 jquery-ui: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 的缩小目标中遇到以下错误:

[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上面提到的...

【问题讨论】:

  • 我建议你为exec-maven-plugin打开一个单独的问题。

标签: maven maven-antrun-plugin


【解决方案1】:

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

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

【讨论】:

  • 哦,对了……ant任务应该是什么样子的呢?请参阅上面的编辑我的 pom.xml
  • 您是否尝试添加dir 属性,如我的示例所示?
  • 您可以将target 替换为${project.build.directory}。我会附加一些告诉您目录用途的内容,例如jquery-ui.
  • An Ant BuildException has occured: Basedir /home/danny/myproject/target/jquery-ui does not exist 我需要在 WEB-INF 旁边有一个资源文件夹才能拥有正确的文件夹结构来访问资源。
  • 该错误是由target/jquery-ui 目录不存在引起的。我已将上面的示例更改为首先创建目录。可以使用 Ant 的 mkdir 任务。
【解决方案2】:

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

【讨论】:

  • 但是使用 jquery ui 提供的 build.xml 会更加动态。如果文件夹结构/文件的某些更改将被添加等等我总是必须更新我的代码......
猜你喜欢
  • 1970-01-01
  • 2011-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多