我們有一個Jenkins作業來測試我們的應用程序。執行時,我們會在執行我們的目標時使用着名的OutOfMemoryError,並使用以下代碼片段生成junitreport。從ANT運行junitreport時出現OutOfMemoryError
<junitreport todir="${tmp.dir}/reports-test-shared">
<fileset dir="${tmp.dir}/reports-test-shared">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="html" />
</junitreport>
我們得到的確切堆棧跟蹤如下。
/app/ci/jenkins/jobs/FLEETperfect Trunk Junit Test MOS/workspace/trunk/com.bsiag.fleet.build/build.xml:818: java.lang.OutOfMemoryError: Java heap space
at com.sun.org.apache.xerces.internal.util.XMLStringBuffer.append(XMLStringBuffer.java:205)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanData(XMLEntityScanner.java:1380)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanCDATASection(XMLDocumentFragmentScannerImpl.java:1654)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2986)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
at org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator.createDocument(XMLResultAggregator.java:254)
at org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator.execute(XMLResultAggregator.java:144)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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)
編輯:在我們的build.xml 818線以上
所示的junitreport任務我已經看過一些在其他SO問題,如here,here和here給出的建議。
最常給出的建議是在JAVA_OPTS
- 增加-Xms和X毫秒
- 增加XMX和X毫秒在ANT_OPTS
這是我迄今所做的:
- 將env變量JAVA_OPTS設置爲「-Xms512m -Xmx2048m」 個
- 設置環境變量ANT_OPTS爲 「-Xms512m -Xmx2048m」 在tomcat的/ bin目錄
- 創建setenv.sh在那裏我做:出口JAVA_OPTS = 「$ JAVA_OPTS -Xms512m -Xmx2048m」
- 新增「-XX: MaxPermSize = 256m「來設置變量JAVA_OPTS和ANT_OPTS
我的問題如下。我不知道我做的內存設置是ANT用來運行報告生成的內存設置(junitreport)
我必須增加堆大小才能讓junitreport終止OutOfMemoryError?
這不完全是一個詹金斯的問題..我已經重申爲您找到合適的專家 –
這是在build.xml中的818行junitreport任務嗎? –
@PulakAgrawal:謝謝! – Tobias