【问题标题】:Handling jQuery + jQuery UI resources with maven使用 maven 处理 jQuery + jQuery UI 资源
【发布时间】:2012-04-05 02:20:03
【问题描述】:

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

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

如您所见,src/main/webapp/resources 中有 js。 我正在使用 scm 插件来查看这些 GitHub 存储库:

https://github.com/jquery/jquery

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

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

这是我的 pom.xml 的必要 sn-p:

<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脚本的问题here

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 -&gt; $2" 会导致:test: /home/danny/myproject/target/jquery-ui/build/dist/jquery-ui-1.9pre/ui/jquery-ui.js -&gt; /home/danny/myproject/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js 但为什么呢?

EDIT2I pulled a request to jquery-ui to fix this

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

这里最好的方法是什么?

【问题讨论】:

    标签: jquery maven jquery-ui exec-maven-plugin maven-antrun-plugin


    【解决方案1】:

    我会向您的“maven-antrun-plugin”添加另一个执行,它运行一个 ant 'move' 命令并移动您需要的所有内容。

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

    1. 尝试将其绑定到'package'并查看它是否在war:excluded之后运行
    2. 将其绑定到预集成测试。它与集成测试无关,但至少您可以确信它在 war:excluded 之后运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多