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"/>




  • 相关阅读:
    如何方便的下载youtube视频?
    88. Merge Sorted Array
    83. Remove Duplicates from Sorted List
    70. Climbing Stairs
    用opencv+python全屏进行显示图片
    58. Length of Last Word
    numpy的resize和reshape区别
    Opencv的绘图
    Python的slice问题
    jqgrid一次性加载
  • 原文地址:https://www.cnblogs.com/markjiao/p/1399031.html
Copyright © 2011-2022 走看看