2010-01-12 74 views
9

我使用Maven站點:運行生成的Cobertura代碼覆蓋...的Maven的Cobertura的OutOfMemoryError

以下是我的Cobertura配置的pom.xml:

<reporting> 
    ... 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>cobertura-maven-plugin</artifactId> 
      <version>2.3</version> 
     </plugin> 
    </plugins> 
</reporting> 

但是我在得到的OutOfMemoryError網站結束:運行。請建議如何擺脫這個錯誤。 (我已經嘗試了所有的-Xmx,-XX選項...)

Exception in thread "Thread-0" java.lang.OutOfMemoryError: Java heap space 
     at sun.reflect.GeneratedSerializationConstructorAccessor74.newInstance(Unknown Source) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
     at java.io.ObjectStreamClass.newInstance(ObjectStreamClass.java:924) 
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1737) 
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) 
     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) 
     at java.util.HashMap.readObject(HashMap.java:1030) 
     at sun.reflect.GeneratedMethodAccessor347.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) 
     at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849) 
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) 
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) 
     at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) 
     at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:480) 
     at net.sourceforge.cobertura.coveragedata.CoverageDataContainer.readObject(CoverageDataContainer.java:373) 
     at sun.reflect.GeneratedMethodAccessor348.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) 
     at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849) 
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) 
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) 
     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) 
     at java.util.HashMap.readObject(HashMap.java:1030) 
     at sun.reflect.GeneratedMethodAccessor347.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) 
     at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849) 
     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) 
+0

杜佩:http://stackoverflow.com/questions/1920059/maven -throws-java-lang-outofmemoryerror – 2010-01-12 20:29:56

回答

15

使用這個屬性在你的pom.xml:

<project> 
... 
<build> 
... 
</build> 

<properties> 
    <cobertura.maxmem>256M</cobertura.maxmem> 
</properties> 

</project> 
+0

我明白了!在pom.xml中添加 512m解決了我的問題。謝謝大家 – KrishPrabakar 2010-02-19 08:52:46

+0

然後考慮投票並接受Jean-Philippe Briend的答案。 – ewernli 2010-02-19 09:55:06

1

你嘗試類似export MAVEN_OPTS=-Xmx1024m(或匹配你的機器的最高值)?

如果您仍然沒有足夠的內存來運行maven,那麼我會建議您嘗試禁用其他插件並從測試覆蓋範圍中排除某些類以檢查它是否真的存在內存問題。

<plugin> 
<groupId>org.codehaus.mojo</groupId> 
<artifactId>cobertura-maven-plugin</artifactId> 
<configuration> 
    <instrumentation> 
    <ignores> 
     <ignore>com.example.boringcode.*</ignore> 
    </ignores> 
    <excludes> 
     <exclude>com/example/dullcode/**/*.class</exclude> 
     <exclude>com/example/**/*Test.class</exclude> 
    </excludes> 
    </instrumentation> 
</configuration> 

http://mojo.codehaus.org/cobertura-maven-plugin/usage.html

編輯

其他的想法:

設置以下屬性(見cobertura plugin properties

-Dmaven.cobertura.report.maxmemory=xxx 
-Dmaven.cobertura.instrumentation.maxmemory=xxx 

嘗試使用fork或使用以下內容增加內存。我不確定它是否適用於cobertura,但似乎適用於junit。從這個page片段:

<plugin> 
... 
<configuration> 
<forkMode>pertest</forkMode> 
</configuration> 
</plugin> 

<plugin> 
... 
<configuration> 
... 
<argLine>-Xmx512m -XX:MaxPermSize=256m</argLine> 
</configuration> 
</plugin> 
+0

這是我的MAVEN_OPTS:-XX:MaxPermSize = 512m -Xms128m -Xmx600m(我將其更改爲-Xmx1024m,但出現以下錯誤: 錯誤發生在虛擬機初始化期間 無法爲對象堆預留足夠的空間 無法創建Java虛擬機。) – KrishPrabakar 2010-01-12 12:32:41

+0

嗨ewernli, 我試過了,但仍存在問題...這是我在pom.xml :(I排除的最大包) \t \t <儀器> \t \t \t \t COM/XXX/**/*的Test.class \t \t COM/XXX/YYY /等級/ **/* .class \t \t com/xxx/yyy/common/**/*。類 \t \t \t \t KrishPrabakar 2010-01-19 10:21:32

+0

我知道了!在pom.xml中添加 512m解決了我的問題。感謝大家! – KrishPrabakar 2010-02-19 08:52:28

相關問題