Hybrid View

  1. #1
    Ext JS Premium Member
    Join Date
    Dec 2011
    Posts
    23
    Vote Rating
    1
    paul_wang is on a distinguished road

      0  

    Default How to use sencha.jar with Ant

    How to use sencha.jar with Ant


    Hi,

    I'm trying to run sencha commands from my Ant file using sencha.jar without much success. If I point my classpath to where I installed Sencha then it seems to work but if I just copy sencha.jar and the lib directory it gave me an error.

    I need to know what it is looking for so I can run it on a machine that does not have Sencha Cmd installed.



    I copied from Sencha directory sencha.jar and lib\ to the current directory and this is the output from build.xml
    Code:
    c:\work_tmp>ant dist.sencha
    Buildfile: c:\work_tmp\build.xml
    
    
    dist.sencha:
      [taskdef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
    
    
    BUILD FAILED
    java.lang.NullPointerException
            at com.sencha.command.ConfigOverrideLoader.loadOverrides(ConfigOverrideLoader.java:139)
            at com.sencha.command.ConfigOverrideLoader.getOverride(ConfigOverrideLoader.java:38)
            at com.sencha.command.SenchaConfigManager.checkForOverride(SenchaConfigManager.java:173)
            at com.sencha.command.SenchaConfigManager.getConfig(SenchaConfigManager.java:166)
            at com.sencha.command.SenchaConfigManager.getConfig(SenchaConfigManager.java:57)
            at com.sencha.command.Sencha.<init>(Sencha.java:40)
            at com.sencha.ant.SenchaCommandTask.doExecute(SenchaCommandTask.java:34)
            at com.sencha.ant.BaseAntTask.execute(BaseAntTask.java:21)
            at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
            at org.apache.tools.ant.Task.perform(Task.java:348)
            at org.apache.tools.ant.Target.execute(Target.java:392)
            at org.apache.tools.ant.Target.performTasks(Target.java:413)
            at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
            at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
            at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
            at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
            at org.apache.tools.ant.Main.runBuild(Main.java:811)
            at org.apache.tools.ant.Main.startAnt(Main.java:217)
            at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
            at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
    
    
    Total time: 0 seconds
    
    
    BUILD FAILED
    c:\work_tmp\build.xml:17: com.sencha.exceptions.BasicException
            at com.sencha.exceptions.BasicException.wrap(BasicException.java:43)
            at com.sencha.ant.BaseAntTask.execute(BaseAntTask.java:25)
            at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
            at org.apache.tools.ant.Task.perform(Task.java:348)
            at org.apache.tools.ant.Target.execute(Target.java:392)
            at org.apache.tools.ant.Target.performTasks(Target.java:413)
            at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
            at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
            at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
            at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
            at org.apache.tools.ant.Main.runBuild(Main.java:811)
            at org.apache.tools.ant.Main.startAnt(Main.java:217)
            at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
            at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
    Caused by: java.lang.NullPointerException
            at com.sencha.command.ConfigOverrideLoader.loadOverrides(ConfigOverrideLoader.java:139)
            at com.sencha.command.ConfigOverrideLoader.getOverride(ConfigOverrideLoader.java:38)
            at com.sencha.command.SenchaConfigManager.checkForOverride(SenchaConfigManager.java:173)
            at com.sencha.command.SenchaConfigManager.getConfig(SenchaConfigManager.java:166)
            at com.sencha.command.SenchaConfigManager.getConfig(SenchaConfigManager.java:57)
            at com.sencha.command.Sencha.<init>(Sencha.java:40)
            at com.sencha.ant.SenchaCommandTask.doExecute(SenchaCommandTask.java:34)
            at com.sencha.ant.BaseAntTask.execute(BaseAntTask.java:21)
            ... 17 more
    
    
    Total time: 0 seconds
    
    
    c:\work_tmp>
    This is the content of build.xml
    Code:
    <project name="work_tmp" default="dist.sencha" basedir=".">
    
    
      <target name="dist.sencha">
    
    
        <path id="sencha.class.path2">
          <fileset dir="c:\Program Files (x86)\SenchaCmd-3.0.0.181\Sencha\Cmd\3.0.0.181\lib" includes="*.jar"/>
          <fileset dir="c:\Program Files (x86)\SenchaCmd-3.0.0.181\Sencha\Cmd\3.0.0.181\" includes="*.jar"/>
        </path>
        
        <path id="sencha.class.path">
          <fileset dir="lib" includes="*.jar"/>
          <fileset dir="." includes="sencha.jar"/>
        </path>
        
        <taskdef resource="com/sencha/ant/antlib.xml" classpathref="sencha.class.path"/>
        
        <x-sencha-command>
          compile
        </x-sencha-command>
        
      </target>
    
    
    </project>
    If I change classpathref="sencha.class.path" to "sencha.class.path2" then it seems to work fine. This is the output.
    Code:
    c:\work_tmp>ant dist.sencha
    Buildfile: c:\work_tmp\build.xml
    
    
    dist.sencha:
      [taskdef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
    [x-sencha-command] sencha compile
    [x-sencha-command]
    [x-sencha-command]
    [x-sencha-command] This command category provides JavaScript compilation commands. The
    [x-sencha-command] compile
    [x-sencha-command]
    [x-sencha-command] category maintains compilation state across its sub-commands so using
    [x-sencha-command] and
    [x-sencha-command]  to
    [x-sencha-command] connect sub-commands can provide significant time savings compared to making
    [x-sencha-command] repeated calls.
    [x-sencha-command]
    [x-sencha-command]
    [x-sencha-command] OPTIONS
    [x-sencha-command]
    [x-sencha-command]   *
    [x-sencha-command] --classpath
    [x-sencha-command] ,
    [x-sencha-command] -cl
    [x-sencha-command]  - adds fodler(s) to the class path
    [x-sencha-command]   *
    [x-sencha-command] --debug
    [x-sencha-command] ,
    [x-sencha-command] -deb
    [x-sencha-command]  - enables the debug option for the js directive parser
    [x-sencha-command]   *
    [x-sencha-command] --deferred-overrides
    [x-sencha-command] ,
    [x-sencha-command] -def
    [x-sencha-command]  - enable / disable deferred override processing (use with optimize)
    [x-sencha-command]   *
    [x-sencha-command] --ignore
    [x-sencha-command] ,
    [x-sencha-command] -ig
    [x-sencha-command]  - excludes files with names containing the given substrings from the class path (comma separated)
    [x-sencha-command]   *
    [x-sencha-command] --options
    [x-sencha-command] ,
    [x-sencha-command] -o
    [x-sencha-command]  - sets options for the js directive parser (name:value,...)
    [x-sencha-command]
    [x-sencha-command] COMMANDS
    [x-sencha-command]
    [x-sencha-command]   *
    [x-sencha-command] concatenate
    [x-sencha-command]  - produce a concatenated build
    [x-sencha-command]   *
    [x-sencha-command] exclude
    [x-sencha-command]  - exclude files from the compilation set
    [x-sencha-command]   *
    [x-sencha-command] include
    [x-sencha-command]  - include files into the compilation set
    [x-sencha-command]   *
    [x-sencha-command] intersect
    [x-sencha-command]  - create a new save set by intersecting existing sets
    [x-sencha-command]   *
    [x-sencha-command] metadata
    [x-sencha-command]  - produce class metadata
    [x-sencha-command]   *
    [x-sencha-command] page
    [x-sencha-command]  - compiles a page
    [x-sencha-command]   *
    [x-sencha-command] restore
    [x-sencha-command]  - alias for 'exclude +all and include -set=<set-name>'
    [x-sencha-command]   *
    [x-sencha-command] save
    [x-sencha-command]  - remembers the currently enabled file state by a name
    [x-sencha-command]   *
    [x-sencha-command] show-ignored
    [x-sencha-command]  - displays ignored files from the current classpath
    [x-sencha-command]   *
    [x-sencha-command] union
    [x-sencha-command]  - alias for 'exclude +all and include ...'
    [x-sencha-command]
    
    
    BUILD SUCCESSFUL
    Total time: 1 second
    
    
    c:\work_tmp>

  2. #2
    Ext JS Premium Member
    Join Date
    Dec 2011
    Posts
    23
    Vote Rating
    1
    paul_wang is on a distinguished road

      1  

    Default


    Ah, I found the file it wants. It's looking for sencha.cfg. If I copy the file to the current directory then it works.

    Is there a reason this dependency exists? Thanks.

  3. #3
    Sencha - Ext JS Dev Team dongryphon's Avatar
    Join Date
    Jul 2009
    Posts
    1,294
    Vote Rating
    121
    dongryphon is a name known to all dongryphon is a name known to all dongryphon is a name known to all dongryphon is a name known to all dongryphon is a name known to all dongryphon is a name known to all

      0  

    Default


    Depending on what you are doing with Sencha Cmd, it will need all of the files it installs. Obviously, some of these files are needed by certain functions you might not need so you can pick some things out here and there. This will be maintenance intensive as you upgrade since there is no good way to subset things to support certain functional subsets.

    If I may ask, what is the issue with running the installer on the machine? We would like to know because obviously this is the kind of environment we want to support.
    Don Griffin
    Ext JS Development Team Lead

    Check the docs. Learn how to (properly) report a framework issue and a Sencha Cmd issue

    "Use the source, Luke!"

  4. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    83
    Vote Rating
    5
    mpost is on a distinguished road

      0  

    Default


    I'm running into similar issues. I don't want to run the installer on every machine because that means the entire build farm would need to be upgraded. It would be far, far easier if I could take Sencha Cmd, check it into my third party asset management system (based on Sonatype Nexus), and then pull it down for each build that needs it -- all without modifying the build system. A detailed guide starting from a .tar file would be extremely helpful here.

    edit: And really what I want to do is eventually use it with maven.

  5. #5
    Sencha - Ext JS Dev Team dongryphon's Avatar
    Join Date
    Jul 2009
    Posts
    1,294
    Vote Rating
    121
    dongryphon is a name known to all dongryphon is a name known to all dongryphon is a name known to all dongryphon is a name known to all dongryphon is a name known to all dongryphon is a name known to all

      2  

    Default


    We are looking at Maven deployment for sure, but just are not there yet. So in the interim...

    The Cmd installer is little more than a self-extracting archive that adds the target folder to the PATH (and provides an uninstaller). Once installed, Cmd makes very few assumptions (see http://docs.sencha.com/ext-js/4-1/#!...mmand_advanced for specifics) so you should be able to tar/zip up the installed version and ship it around as you see fit. Keep in mind that the install is platform-specific and contains native binary executables so you can only unzip/tar and run on the same OS.

    I would recommend looking in the build-impl.xml if you want to see how we "boot up" for builds directly from Ant.

    It boils down to these steps:
    1. Find sencha.jar (this could be as simple as a required property)
    2. Load the antlib
    3. Add sencha.jar to the classpath (if required)
    4. Initialize properties from the Cmd configuration (if needed)

    These are exacted from the build-impl.xml:

    Code:
        <taskdef resource="com/sencha/ant/antlib.xml" classpath="${cmd.dir}/sencha.jar"/>
        <x-extend-classpath>
            <jar path="${cmd.dir}/sencha.jar"/>
        </x-extend-classpath>
        <x-sencha-init prefix=""/>
    The "x-extend-classpath" task adds the sencha.jar (pretty obvious). You'll know if you need this if you get errors about not finding classes from there.

    The "x-sencha-init" task loads the app, workspace and other config properties (found in sencha.cfg files) in to Ant properties. The "prefix" prefixes these properties.

    If you are building a script from scratch you may not need "x-sencha-init".

    For what it is worth, we face similar issues for building Cmd as we rely on many things that are not published in a maven repo. We solved this by creating our own (internal) maven repo where we store those artifacts. This allows our Cmd build to treat them as normal maven dependencies.
    Don Griffin
    Ext JS Development Team Lead

    Check the docs. Learn how to (properly) report a framework issue and a Sencha Cmd issue

    "Use the source, Luke!"

  6. #6
    Sencha User
    Join Date
    Sep 2012
    Posts
    83
    Vote Rating
    5
    mpost is on a distinguished road

      0  

    Default


    Thank you, that was quite informative.

  7. #7
    Sencha User
    Join Date
    May 2014
    Posts
    4
    Vote Rating
    0
    nikhil14 is on a distinguished road

      0  

    Default


    Quote Originally Posted by paul_wang View Post
    Ah, I found the file it wants. It's looking for sencha.cfg. If I copy the file to the current directory then it works.

    Is there a reason this dependency exists? Thanks.
    Hi Paul,
    Can you please tell me did you copied the sencha.cfg file manually or included it in ant script?