1

这是我当前的文件夹结构:

 .
 |-- pom.xml
 `-- src
     `-- main
         |-- java
         |   `-- ...
         |-- resources
         |   `-- messages
         |       `-- messages.properties
         |       `-- ...
         |   `-- properties
         |       `-- hibernate.properties
         |       `-- jawr.properties
         |       `-- ...
         |   `-- log4j.xml
         |   `-- tiles.xml
         `-- webapp
             |-- resources
             |   `-- css
             |       `-- ...
             |   `-- images
             |       `-- ...
             |   `-- js
             |       `-- main.js
             |-- WEB-INF
             |   `-- context
             |       `-- application.xml
             |       `-- hibernate.xml
             |       `-- security.xml
             |       `-- servlet.xml
             |   `-- views
             |       `-- ...
             |   `-- redirect.jsp
             |   `-- web.xml

如您所见,jssrc/main/webapp/resources. 我正在使用 scm 插件来查看这些 GitHub 存储库:

https://github.com/jquery/jquery

https://github.com/jquery/jquery-ui

结帐后,我需要使用他们的构建机制来连接和缩小并移动target/jquery/dist/jquery.min.js, target/jquery-ui/build/dist/jquery-ui.min.js,jquery-ui/build/dist/jquery-ui-1.9pre/ui/minified/i18n/jquery-ui-i18n.min.jstarget/myproject-1.0-SNAPSHOT/resources/js.

这是我的 pom.xml 的必要片段:

<plugins>

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>${java.version}</source>
      <target>${java.version}</target>
      <showWarnings>true</showWarnings>
    </configuration>
  </plugin>

  <plugin>
    <artifactId>maven-war-plugin</artifactId>
  </plugin>

  <plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <phase>install</phase>
        <goals>
          <goal>sources</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <artifactId>maven-scm-plugin</artifactId>
    <executions>
      <execution>
        <id>checkout-jquery</id>
        <phase>compile</phase>
        <goals>
          <goal>checkout</goal>
        </goals>
        <configuration>
          <connectionUrl>scm:git:git://github.com/jquery/jquery.git</connectionUrl>
          <checkoutDirectory>${project.build.directory}/jquery</checkoutDirectory>
        </configuration>
      </execution>
      <execution>
        <id>checkout-jquery-ui</id>
        <phase>compile</phase>
        <goals>
          <goal>checkout</goal>
        </goals>
        <configuration>
          <connectionUrl>scm:git:git://github.com/jquery/jquery-ui.git</connectionUrl>
          <checkoutDirectory>${project.build.directory}/jquery-ui</checkoutDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
      <execution>
        <phase>compile</phase>
        <goals>
          <goal>exec</goal>
        </goals>
        <configuration>
          <executable>make</executable>
          <workingDirectory>${project.build.directory}/jquery</workingDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <phase>compile</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <target>
            <ant antfile="build.xml" dir="${project.build.directory}/jquery-ui/build" />
          </target>
        </configuration>
      </execution>
    </executions>
  </plugin>

</plugins>

我只需要以下步骤:

  • 用于exec-maven-plugin使用jquery的concatenating+minifying机制(Makefile)
  • 用于maven-antrun-plugin使用jquery-ui的concatenating+minifying机制(Ant build.xml)
  • 将缩小的 jquery、jquery-ui 和 jquery-ui-i18n js 文件移动到target/myproject-1.0-SNAPSHOT/resources/js
  • 然后执行其他生命周期阶段

但它停止在第 2 步:maven-antrun-plugin. 更具体地说,这里运行外部 shell 脚本的问题:

minify:
     [echo] Building minified
    [mkdir] Created dir: /home/danny/myproject/target/jquery-ui/build/dist/jquery-ui-1.9pre/ui/minified
    [mkdir] Created dir: /home/danny/myproject/target/jquery-ui/build/dist/jquery-ui-1.9pre/ui/minified/i18n
    [mkdir] Created dir: /home/danny/myproject/target/jquery-ui/build/dist/jquery-ui-1.9pre/themes/base/minified
    [apply] build/minify-js.sh: Line 3: /home/danny/myproject/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js: File or folder not found
    [apply] Result: 1
    ...

该脚本查找错误的目录(/home/danny/myproject/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js而不是/home/danny/myproject/target/jquery-ui/build/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js

编辑:问题是:minify-js.sh 得到错误的第二个参数($2)。将此添加到 modify-js.sh:echo "test: $1 -> $2"会导致:test: /home/danny/myproject/target/jquery-ui/build/dist/jquery-ui-1.9pre/ui/jquery-ui.js -> /home/danny/myproject/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js但是为什么呢?

EDIT2我向 jquery-ui 提出了一个请求来解决这个问题

但现在我需要知道如何将缩小的 jquery、jquery-ui 和 jquery-ui-i18n js 文件移动到target/myproject-1.0-SNAPSHOT/resources/jsafter war:excluded.

这里最好的方法是什么?

4

1 回答 1

1

我会在你的'maven-antrun-plugin'中添加另一个执行,它运行一个ant'move'命令并移动你需要的一切。

坦率地说,您必须尝试将其绑定到哪个阶段。我猜测 war:excluded 正在“打包”阶段运行。如果是这样的话,由于 maven 在包和集成测试之间没有步骤,您可以:

  1. 尝试将其绑定到“包”并查看它是否在 war:excluded 之后运行
  2. 将其绑定到预集成测试。它与集成测试无关,但至少你会确信它在 war:excluded 之后运行。
于 2012-03-21T19:45:40.330 回答