1. #1
    Sencha User
    Join Date
    Oct 2010
    Posts
    75
    Vote Rating
    4
    devnullable is on a distinguished road

      0  

    Default Sencha cmd and Maven development

    Sencha cmd and Maven development


    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/showthre...l=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.
    Code:
    <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?

  2. #2
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default


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

  3. #3
    Ext JS Premium Member
    Join Date
    Jan 2012
    Posts
    24
    Vote Rating
    0
    pherris is on a distinguished road

      0  

    Default


    would you mind posting the pertinent lines from your maven config?

  4. #4
    Sencha Premium Member
    Join Date
    Feb 2013
    Posts
    11
    Vote Rating
    0
    sharon@hp is on a distinguished road

      0  

    Default Does this work now?

    Does this work now?


    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!

  5. #5
    Ext JS Premium Member
    Join Date
    Jan 2012
    Posts
    24
    Vote Rating
    0
    pherris is on a distinguished road

      0  

    Default


    I ended up running maven only after I generated the zip first with the sencha command.

  6. #6
    Sencha User skrooks's Avatar
    Join Date
    Dec 2012
    Posts
    6
    Vote Rating
    0
    skrooks is on a distinguished road

      0  

    Default


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

  7. #7
    Sencha User
    Join Date
    Jun 2011
    Posts
    12
    Vote Rating
    0
    nmandya is on a distinguished road

      0  

    Default


    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.

  8. #8
    Sencha User skrooks's Avatar
    Join Date
    Dec 2012
    Posts
    6
    Vote Rating
    0
    skrooks is on a distinguished road

      0  

    Default


    The x-script-def task should be imported via
    Code:
    <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.

  9. #9
    Sencha User
    Join Date
    Jun 2011
    Posts
    12
    Vote Rating
    0
    nmandya is on a distinguished road

      0  

    Default


    Yes, I do have the taskdef in the right place. Below is a snippet of pom.xml

    Code:
                <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

  10. #10
    Sencha User
    Join Date
    Jun 2011
    Posts
    12
    Vote Rating
    0
    nmandya is on a distinguished road

      0  

    Default


    Also, I am using Sencha Cmd 3.1.2.342 and ExtJS 4.2. Thanks.