zoukankan      html  css  js  c++  java
  • Ant Notes of usage and failures

    1. java.lang.OutOfMemoryError
    When javac is compiling a large number of java source files, it may fail with java.lang.OutOfMemoryError:

    The system is out of resources.
    Consult the following stack trace for details.

    java.lang.OutOfMemoryError: Java heap space

    It's no different than OutOfMemoryError in other java applications. When you run javac in Sun JDK, it's invoking com.sun.tools.javac.main.Main located in %JAVA_HOME%\lib\tools.jar.
    If you are compiling with javac task in Apache Ant, set fork attribute to true, to run javac in a separate process with its own heap size settings. If fork is set to false, or not set (default is false), javac will run in the same process as Ant, which has a default maximum heap size of 64m.

    <javac fork="true"srcdir="${basedir}/src"
        destdir="${basedir}/build/classes"
        classpath="${project.classpath}"
        memoryinitialsize="256m"
        memorymaximumsize="256m">
    </javac>
    Setting fork to true will also limit any memory leaks in javac implementation to its own child process, without affecting the parent Ant process.

    If setting fork, memoryInitialSize, and memoryMaximumSize still doesn't fix the problem, you can execute javac task several times, each javac compiling a subset of your source tree. But this should really be the last rescort, since you are now managing source code dependency, which should be javac's business. You will need to decide which modules get compiled first, and classes in certain modules cannot have direct references to classes in certain other modules, and so on. I'd rather increase the memoryMaximumSize to 2g.

    If you don't want to modify existing build.xml files, another option is to increase the heap size for Ant JVM and still execute javac task in-process. You just need to set environment variable ANT_OPTS:

    export ANT_OPTS="-Xms256m -Xmx256m"    (ksh/bash)
    setenv ANT_OPTS="-Xms256m -Xmx256m"    (tcsh/csh)
    set ANT_OPTS="-Xms256m -Xmx256m"       (Windows)

    A disadvantage of this approach is users will need to remember to set this environment variable, or use some sort of wrapper script on top of %ANT_HOME%\bin\ant.bat, or $ANT_HOME/bin/ant.

    If you are invoking javac directly, you can also increase the heap size for the underlying JVM:

    javac -d build/classes -classpath ... -J-Xms256m -J-Xmx256m

    2. Bad version number in .class file
    If .class are compiled with JDK5, it also should use JDK5 to run.
    Note: if you have JDK6 installed, in order to use JDK5, you must remove java.exe in c:\windows\system32.

    3. if doesn't support the nested "echo" element
    Misused the target if.
    <if><not><isset property="server"/></not>
          <echo>**** ERROR, -Dserver parameter is required when calling this target. ****</echo>
    </if>
    shoud be:
    <if><not><isset property="server"/></not>
          <then>
                <echo>**** ERROR, -Dserver parameter is required when calling this target. ****</echo>
          </then>
    </if>
    In my opinion, Ant has a ugly scripting! :)

    4. use propertyregex to operate a string
    http://ant-contrib.sourceforge.net/tasks/tasks/propertyregex.html
    4.1 select a sub string

    <propertyregex property="pack.name"
                  input="package.ABC.name"
                  regexp="package\.([^\.]*)\.name"
                  select="\1"
                  casesensitive="false" />
       
        yields ABC
    4.2 replace a sub string    
    <propertyregex property="pack.name"
                  input="package.ABC.name"
                  regexp="(package)\.[^\.]*\.(name)"
                  replace="\1.DEF.\2"
                  casesensitive="false" />
       
        yields package.DEF.name

    It's to replace all sub strings ${server} in ${arg} with new string ${server2} with case insensitive and put the result string in property arg1. If property arg1 has been set, it will override the value of it. Note that don't use ${arg1} instead of arg1.
    <propertyregex property="arg1" input="${arg}" regexp="${server}" replace="${server2}" override="true" casesensitive="false"/>

    5. use replaceregexp to operate a file
    http://ant.apache.org/manual/OptionalTasks/replaceregexp.html

    <replaceregexp file="${workbench.build.dir}\zip\lc900gm\updateLatestVerified.properties"
            match="version=(.+)" replace="version=${wbbuild}" byline="true"/>




  • 相关阅读:
    MFC中添加自己定义的消息
    动态创建的list control添加消息响应
    关于CString的奇怪问题
    如何去掉按钮在输入焦点切换时所产生的闪烁
    wince中将自己的应用程序编译到内核并开机启动的一种方法
    wince下圆角矩形按钮的实现
    关于error C2471:无法更新程序数据库的错误的解决方法
    关于烧写开机logo之后导致无法启动系统的问题
    利用IdHTTP进行多线程下载
    TEdit 控件的提示,就像 IE7 的地址输入栏一样
  • 原文地址:https://www.cnblogs.com/markjiao/p/1399031.html
Copyright © 2011-2022 走看看