During creating a war-package, on 'prepare-package' phase, I run 'secnha ant build' by using exec-maven-plugin to make a production build of ExtJS 4 app. I don't want to pollute ${basedir}/src/main/webapp directory so I have changed workspace.build.dir(in ${basedir}/src/main/webapp/.sencha/workspace/sencha.cfg) to ${basedir}/target. This works relatively fine. There are some bugs which are reported on the forum. For example some image urls generated are absolute not relative.

After succesful build, build directory contains index.html, all-classes.js and ext and resources directories. I use ant copy tasks to copy files back to ${basedir}/src/main/webapp directory so that they are included in war package.

However I am not sure what to do with the ext and resources directories. I just cannot copy them to ${basedir}/src/main/webapp because it already has those directories generated by Sencha Cmd and are used during development. 'sencha ant build' generated ext and resources directories are not identical with directories generated initially by 'sencha generate app'.

Is there anyone who has same kind of setup? How do you handle the situation?

Here are a few things I've found. The approach I've tried so far is to use maven-antrun-plugin to invoke Sencha Cmd as an Ant Library. Check the Sencha API docs under Ant Integration for some helpful details.

First, you need to define a cmd.dir property specifying where Sencha Cmd is located.

Code:

<properties>
<cmd.dir>path/to/Sencha/Cmd</cmd.dir>
</properties>

It may be helpful to have an environment variable to help define this path. Alternatively, you could copy/deploy Sencha Cmd to your project structure somewhere and exclude it from your war.

To make use of Sencha Cmd Ant tasks, you need to reference the sencha.jar file via a taskdef. You can then use <x-sencha-command> tasks to invoke Sencha Cmd as needed. Since Sencha Cmd is Ant driven, it sometimes bootstraps using a build.xml file located with the web app files. This build file is likely in a different location than your pom.xml file, meaning Ant wouldn't normally be able to see its build.xml file when run via Maven since the working directory would be based on the location of the pom file. To fix this issue, specify a dir attribute on the <x-sencha-cmd> tag to set the working directory for Sencha Cmd invocations. When using <x-sencha-command>, the arguments are placed in the body text, one argument per line. Spaces are trimmed at both ends, so indent level is not significant but recommended to clarify the command structure.

I have the exact same configuration, but everytime I run Maven, I am getting the error below. Any ideas?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (sencha-compile) on project webapp: An Ant BuildException has occured: com.sencha.exceptions.BasicException: Problem: failed to create task or type x-script-def
[ERROR] Cause: The name is undefined.
[ERROR] Action: Check the spelling.
[ERROR] Action: Check that any custom tasks/types have been declared.
[ERROR] Action: Check that any <presetdef>/<macrodef> declarations have taken place.