这是我当前的文件夹结构:
.
|-- 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
如您所见,js
在src/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.js
到target/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/js
after war:excluded
.
这里最好的方法是什么?