【问题标题】:How to speed up Alfresco Share development如何加快 Alfresco Share 开发
【发布时间】:2013-01-11 14:27:38
【问题描述】:

我正在开发并在 Share 上执行一些自定义操作。我的 IDE 是 Eclipse Juno,工作区由以下元素组成:

  • 露天网络项目
  • 扩展 Java 项目
  • 分享网络项目

alfresco 和 share web 项目都部署在单独的 Tomcat 实例中,这样我可以通过仅重新启动部署 Share 的 Tomcat 实例来稍微加快我的开发任务。

我的扩展 Java 项目与 Alfresco 提出的 Eclipse 项目具有相同的结构。 Y 提供的 Ant 任务,用于在 Tomcat 中编译、压缩 JavaScript 文件、打包和部署生成的 JAR 文件。

我正在开发一些新的 JavaScript 客户端小部件,这意味着每次我进行更改时,我都必须停止 Tomcat,启动 Ant 构建脚本并重新启动,因为我必须经常这样做,你可以猜到它正在成为一种痛苦。我只是想知道是否有任何方法可以加快 Share 上的开发任务。 Alfresco 开发团队是如何做到的?他们搭建了什么样的环境?

我正在考虑创建一个新的 Ant 目标,它将扩展项目的内容热部署到已部署的 Share web 项目中,当然要考虑路径;顺便说一句,该机制必须允许反向操作。那会可行吗?我们的想法是拥有与开发常规 Web 项目时类似的部署机制:当您进行任何更改时,您只需按下“发布”按钮,更改就会被填充到服务器中。

我想知道一些技巧和想法,如果可能的话,特别是来自 Alfresco 开发团队。

PS:我已经看过https://forums.alfresco.com/en/viewtopic.php?f=47&t=44850https://forums.alfresco.com/en/viewtopic.php?f=48&t=18749

【问题讨论】:

    标签: share development-environment alfresco


    【解决方案1】:

    有两件事可以大大加快速度:

    • 投资 jrebel 许可证,无需重新启动服务器即可重新加载类http://zeroturnaround.com/software/jrebel/

    • 构建 ant 任务,将 webscripts 复制到目标文件夹,并在必要时使用 curl 重新加载 webscripts。

    重新加载 Alfresco Share webscript 的任务示例:

    <target name="deploy-share-webscripts" depends="Share: Copy files" description="Refreshes the list of webscripts">
        <exec executable="curl">
        <arg value="-d"/>
        <arg value="reset=on"/>
        <arg value="http://admin:admin@${share.web.url}/page/console?reset=webscripts"/>
        </exec>
    </target>
    

    附加ant任务的复制部分(src-dirs在构建文件的开头被声明为属性):

        <echo message="- Copying java classes" />
        <copy todir="${warWebappTargetClasses}" overwrite="false" verbose="true">
            <fileset dir="${warTargetJavaDir}" />
        </copy>
    
        <echo message="- Copying resource files" />
        <copy todir="${warWebappTargetClasses}" overwrite="false" verbose="true">
            <fileset dir="${warSrcResourcesDir}" >
                <include name="**/model/*"/>
                <include name="**/templates/**/*"/>
                <include name="**/custom-model-context.xml"/>
                <include name="**/web-client-config-custom.xml"/>
                <include name="**/webclient.properties"/>
                <include name="**/aka-model-resourcebundle*"/>
                <include name="log4j.properties"/>
            </fileset>
        </copy>
    
        <echo message="- Copying resource files from amp into war for quick deployment." />
        <copy todir="${warWebappTargetClasses}" overwrite="false" verbose="true">
            <fileset dir="${projectAmpResourcesSrcDir}" />
            <fileset dir="${projectAmpClassesDir}" />
    
            <fileset dir="${listmanagerAmpResourcesSrcDir}" />
    
        </copy>
    
        <echo message="- Copying config files from amp into war for quick deployment." />
        <copy todir="${warWebappTargetClasses}\alfresco\module\Project-amp\" overwrite="false" verbose="true">
    
            <fileset dir="${projectAmpConfigSrcDir}" />
    
    
        </copy>
    </target>
    

    我使用 maven alfresco 生命周期 http://wiki.alfresco.com/wiki/Managing_Alfresco_Lifecyle_with_Maven 进行设置,这也加快了速度。我相信这个主题可以添加很多内容。

    【讨论】:

    • 除了类重新加载(在这个阶段对我来说不太重要),你的意思是创建一个 Ant 任务,将扩展资源复制到 Tomcat 内的 Share 部署文件夹中,我错了吗?例如,客户端资源将被复制到 tomcat/webapps/share/WebContent/my_resources_folder/...,或自定义页面到 tomcat/webapps/share/WebContent/WEB-INF /classes/alfresco/site-data/pages/my_custom_page.xml。如果是您的意思,是否有此类 Ant 任务的示例? :)
    • 好的,将复制部分添加到我的答案中,因为评论部分的代码格式不理想......
    • 还有一个问题@erik-b,当你谈到“目标文件夹”时,你到底是什么意思?
    • @AlejandroGarcíaSeco,我正在引用构建的输出文件夹,也就是类路径。这是tomcat在运行时查找文件的地方。我将它命名为目标,因为这是使用 maven 时输出文件夹的默认名称。对你来说,它可能是 bin 文件夹或类似的东西。
    【解决方案2】:

    您可以通过为 tomcats 共享类加载器配置其他路径来避免将 webscripts 复制到 tomcat。这是tomcat/conf/catalina.properties 中的设置。我直接将它设置到项目源目录,因此不需要编译步骤。

    shared.loader=${catalina.home}/shared/classes,${catalina.home}/shared/lib/*.jar,\
    /path/to/my/dashlet/src/main/resources,\
    

    我在shared/classes/alfresco/web-extension/share-config-custom.xml 中还有以下设置来启用模板和网页脚本的自动刷新。

    <alfresco-config>
        <!-- Global config section -->
        <config replace="true">
            <flags>
                <!-- Developer debugging setting - DEBUG mode for client scripts in the browser -->
                <client-debug>true</client-debug>
    
                <!-- LOGGING can be toggled at runtime when in DEBUG mode (Ctrl, Ctrl, Shift, Shift).
                     This flag automatically activates logging on page load. -->
                <client-debug-autologging>false</client-debug-autologging>
            </flags>
        </config>
    
        <config evaluator="string-compare" condition="WebFramework">
            <web-framework>
                <!-- Autowire Runtime Settings -->
                <autowire>
                    <!--
                        Developers can set mode to 'production' or 'development' (to disable; SpringSurf caches,
                        FreeMarker template caching and Rhino JavaScript compilation.)
                    -->
                    <mode>development</mode>
                </autowire>
            </web-framework>
        </config>
    </alfresco-config>
    

    【讨论】:

    • 据我了解,这与服务器端 webscripts 开发更相关(如果我错了,请纠正我)。我的问题更侧重于客户端资源,例如 JavaScript 小部件。无论如何,您提供的内容非常有用,我会将其合并到我的开发环境中。谢谢。
    • @AlejandroGarcíaSeco:至少对于 dashlets,客户端部分也打包在 jar 中,然后在类路径中可用。将共享类加载器设置为您的源目录就无需复制和打包。我不确定您的情况是否需要我的答案的第二部分,可能是它还禁用了类路径资源的某些缓存。
    • 我一直在尝试您的建议,但不幸的是对我来说无法正常工作。当根据一些自定义评估程序初始化 Spring 上下文时,我遇到了异常,我一直在尝试对其进行整理,但我无法找到一个直接的解决方案。我会再试一次,因为我现在不能花更多时间在这上面。谢谢一百万。
    【解决方案3】:

    这就是我预期的 100% 有效的解决方案。在@erik-b 和@jorn-horstmann 的回答之后,我想到了这个,并考虑了我读过的一些帖子。

    所以基本上我有了下一个 Ant 目标,它可以热部署我的 Share 扩展 Java 项目的内容:

    <!--
        Hot copy individual files into appropriate deployment folder (e.g. $TOMCAT_HOME/webapps/share)
    -->
    <target name="hotdeploy-tomcat-share" depends="clean, prepare, build-jar" description="Hot copy individual files into appropriate deployment folder (e.g. $TOMCAT_HOME/webapps/share)">
        <echo message="Generating and deploying JAR file with custom configuration files" />
        <jar destfile="${dist.dir}/${jar.name}">
            <!-- Only including configuration XML files such as share-config-custom.xml -->
            <fileset dir="${build.jar.dir}" includes="**/META-INF/*.xml" />
        </jar>
        <copy todir="${tomcat.share.deployment.path}/WEB-INF/lib">
            <fileset file="${dist.dir}/${jar.name}" />
        </copy>
    
        <echo message="Hot deploying Share files" />
        <copy todir="${tomcat.share.deployment.path}/WEB-INF/classes" includeEmptyDirs="false">
            <fileset dir="${build.jar.dir}">
                <patternset refid="hotdeploy-tomcat-patternset" />
            </fileset>
        </copy>
    </target>
    

    必须禁用自动重新加载模块功能,否则每次执行上述 Ant 目标时,Tomcat 都会重新加载 Share 和其他部署的 Web 应用程序。另外,我相信在 $TOMCAT_HOME/shared/ 目录下也可以热部署,但我还没有尝试过。

    我用于开发扩展的 Java 项目是这个模型项目:http://code.google.com/p/share-extras/wiki/SampleProject。有完整的构建脚本以及所需的其他目标。

    我也在我的 share-config-custom.xml 中使用它:

       <!-- Global config section -->
       <config replace="true">
          <flags>
             <!--
                Developer debugging setting to turn on DEBUG mode for client scripts in the browser
             -->
             <client-debug>true</client-debug>
    
             <!--
                LOGGING can always be toggled at runtime when in DEBUG mode (Ctrl, Ctrl, Shift, Shift).
                This flag automatically activates logging on page load.
             -->
             <client-debug-autologging>false</client-debug-autologging>
          </flags>
       </config>
    
       <config evaluator="string-compare" condition="WebFramework">
          <web-framework>
             <!-- SpringSurf Autowire Runtime Settings -->
             <!-- 
                  Developers can set mode to 'development' to disable; SpringSurf caches,
                  FreeMarker template caching and Rhino JavaScript compilation.
             -->
             <autowire>
                <!-- Pick the mode: "production" or "development" -->
                <mode>development</mode>
             </autowire>
    
             <!-- Allows extension modules with <auto-deploy> set to true to be automatically deployed -->
             <module-deployment>
                <mode>manual</mode>
                <enable-auto-deploy-modules>true</enable-auto-deploy-modules>
             </module-deployment>
          </web-framework>
       </config>
    

    例如,最后一个 XML sn-p 避免在对 FTL 页面执行任何更改后刷新 webscript。

    我也使用 JRebel 进行了一些测试,但根据我的经验,我会说它对 Share 开发没有多大帮助。

    接下来的文章还有有趣的东西:

    http://blogs.alfresco.com/wp/kevinr/2010/04/07/developer-tips-for-alfresco-share-33/

    http://techblog.zabuchy.net/2012/debugging-javascript-in-alfresco/

    希望对他人有所帮助。

    【讨论】:

      【解决方案4】:

      我通常在私有实例上工作,这样我就能负担得起运行爆炸式应用程序的费用,因此我可以立即看到任何更改。当我更改数据模型、部署一些新的 java 支持的模块或 webscript 或类似时,我只需要重新启动 tomcat。尽管其中一些也可以实时重新加载。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多