PDA

View Full Version : Sencha cmd and Maven development



devnullable
14 Oct 2012, 8:09 PM
Hi,


I have a Maven based web application which uses typical Maven directory structure. I have created an Ext JS 4.1.1a application to ${basedir}/src/main/webapp directory using Sencha Cmd 3.0.0.190.


For development purposes I use maven-jetty-plugin and generated index.html which uses Ext.Loader to load scripts dynamically. There's a bug http://www.sencha.com/forum/showthread.php?244464-4.1.1-Controller-s-modules-load-problem&p=897523&viewfull=1#post897523 which is fortunately easy to fix.


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.
<target name="-after-build">
<copy file="${workspace.build.dir}/all-classes.js" tofile="all-classes.js"/>
<copy file="${workspace.build.dir}/index.html" tofile="index.jsp"/>
</target>


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?

ykey
15 Oct 2012, 4:26 AM
I am doing something very similar and waiting for an updated version of Sencha command.

I think you can avoid the extra copy back into the webapp directory by just telling the war plugin about additional webResources (the sencha build directory).

pherris
30 Jan 2013, 10:00 AM
would you mind posting the pertinent lines from your maven config?

sharon@hp
15 Feb 2013, 12:58 PM
I would like to do a very similar thing (integrate Sencha Cmd with Maven). Please post details of your solution if you were able to get it working. Thanks!

pherris
20 Mar 2013, 6:22 PM
I ended up running maven only after I generated the zip first with the sencha command.

skrooks
11 Apr 2013, 10:08 AM
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 (http://docs.sencha.com/ext-js/4-1/#!/guide/command_ant) for some helpful details.

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

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

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<taskdef resource="com/sencha/ant/antlib.xml" classpath="${cmd.dir}/sencha.jar"/>
<x-sencha-command dir="${basedir}/src/main/webapp">
app
build
</x-sencha-command>
</target>
</configuration>
</execution>
</executions>
</plugin>


If you need more customization beyond the default build, you could try the various "sencha compile" commands.

nmandya
25 Jun 2013, 8:53 AM
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.

skrooks
25 Jun 2013, 9:36 AM
The x-script-def task should be imported via

<taskdef resource="com/sencha/ant/antlib.xml" classpath="${cmd.dir}/sencha.jar"/>
Make sure that line gets called in your <target> tag before invoking any of the x-whatever Ant tasks defined by Sencha.

nmandya
25 Jun 2013, 9:40 AM
Yes, I do have the taskdef in the right place. Below is a snippet of pom.xml



<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>sencha-compile</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<target>
<taskdef resource="com/sencha/ant/antlib.xml">
<classpath>
<pathelement location="${cmd.dir}/sencha.jar"/>
</classpath>
</taskdef>
<x-sencha-init dir="${basedir}/src/main/webapp"/>
<x-sencha-command dir="${basedir}/src/main/webapp">
app
build
</x-sencha-command>
</target>
</configuration>
</plugin>

The other thing I notice is that the exception is originating because of something in plugins.xml.

Caused by: /home/builder/bin/Sencha/Cmd/3.1.2.342/plugin.xml:15: Problem: failed to create task or type x-script-def

nmandya
25 Jun 2013, 9:50 AM
Also, I am using Sencha Cmd 3.1.2.342 and ExtJS 4.2. Thanks.

skrooks
25 Jun 2013, 12:04 PM
What's above the "BUILD FAILURE" line of your build output? For example, if the path to cmd.dir is wrong, I get a message stating

Could not load definitions from resource com/sencha/ant/antlib.xml. It could not be found.
Then I get the error you're seeing. Check your path for cmd.dir.

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

nmandya
25 Jun 2013, 6:10 PM
I know that the cmd.dir is correct and that the antlib.xml file from sencha.jar does get loaded. When I run the maven command with the -X flag, I can see this in the logs:

Class org.apache.tools.ant.taskdefs.optional.script.ScriptDef loaded from parent loader (parentFirst)
Class com.sencha.ant.ScriptTask loaded from ant loader (parentFirst)
+Datatype x-script-def com.sencha.ant.ScriptTask

5nc5
6 Nov 2013, 3:56 AM
Hi,

first of all, thank you very much. This thread helped me very much!
My maven ant task run!

Now i uploaded the sencha.jar to a local maven repository. So i have a maven dependency which references and downloads the sencha.jar. That works fine too!
But what to do reference within the pom to this sencha.jar.
Now i have


<properties> <cmd.dir>path/to/Sencha/Cmd</cmd.dir> </properties> which points to my local disc. How can i point to the sencha.jar that i download from my maven repository? Any idea?
Thanks!
EDIT:
Now i tried the following:


<configuration>
<target>
<!-- <property name="sencha_cmd_loc" refid="com.sencha.cmd:sencha-cmd:jar"/> -->
<property name="sencha_cmd_loc" value="${maven.dependency.com.sencha.cmd.sencha-cmd.jar.path}"/>
<echo message="Where: ${sencha_cmd_loc}"/>
<taskdef resource="com/sencha/ant/antlib.xml" classpath="${sencha_cmd_loc}"/>
<x-sencha-command dir="${basedir}/src/main/webapp">
app
build
</x-sencha-command>
</target>
</configuration>

But maven faild with this error message:
Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project blabla-project: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] jar:file:/home/blabla/.m2/repository/com/sencha/cmd/sencha-cmd/4.0.0.203/sencha-cmd-4.0.0.203.jar!/com/sencha/ant/antlib.xml:12: taskdef A class needed by class com.sencha.ant.InitTask cannot be found: org/slf4j/LoggerFactory
[ERROR] using the classloader AntClassLoader[/home/blabla/.m2/repository/com/sencha/cmd/sencha-cmd/4.0.0.203/sencha-cmd-4.0.0.203.jar]
[ERROR] around Ant part ...<taskdef resource="com/sencha/ant/antlib.xml" classpath="${sencha_cmd_loc}"/>... @ 6:80 in /home/blabla/workspace/if-app-ursurs/target/antrun/build-main.xml: org.slf4j.LoggerFactory
[ERROR] -> [Help 1]

The path of the jar is right, but wha about the "!" in the path? maybe this is the problem ...
Thanks for helping ...

testingarchitect
26 Jul 2014, 4:33 AM
I know this is like a year old, but any chance you found a solution to this issue (A class needed by class com.sencha.ant.InitTask cannot be found: org/slf4j/LoggerFactory)?