最近在eclipse-jee-luna-SR2-win32开发环境(java version:1.7.0_60)下导入JEECG3.5.2开源项目过程中发现在build workspace过程中报Internal Error,查看workspace文件夹下的.metadata文件夹中的.log文件发现有下面的错误:

!ENTRY org.eclipse.core.jobs 4 2 2015-08-04 18:37:10.621
!MESSAGE An internal error occurred during: "Building workspace".
!STACK 0
java.lang.OutOfMemoryError: Java heap space
 at org.eclipse.wst.jsdt.internal.core.index.DiskIndex.readStreamChars(DiskIndex.java:884)
 at org.eclipse.wst.jsdt.internal.core.index.DiskIndex.readCategoryTable(DiskIndex.java:632)
 at org.eclipse.wst.jsdt.internal.core.index.DiskIndex.addQueryResults(DiskIndex.java:199)
 at org.eclipse.wst.jsdt.internal.core.index.Index.query(Index.java:154)
 at org.eclipse.wst.jsdt.internal.core.search.matching.FieldPattern.queryIn(FieldPattern.java:330)
 at org.eclipse.wst.jsdt.internal.core.search.matching.InternalSearchPattern.findIndexMatches(InternalSearchPattern.java:92)
 at org.eclipse.wst.jsdt.internal.core.search.matching.OrPattern.findIndexMatches(OrPattern.java:59)
 at org.eclipse.wst.jsdt.internal.core.search.matching.MatchLocator.findIndexMatches(MatchLocator.java:407)
 at org.eclipse.wst.jsdt.internal.core.search.PatternSearchJob.search(PatternSearchJob.java:116)
 at org.eclipse.wst.jsdt.internal.core.search.PatternSearchJob.execute(PatternSearchJob.java:66)
 at org.eclipse.wst.jsdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:280)

......

在网上有不少关于这个错误的解决方案,试了几个都没有效果。大致思路都是通过修改Eclipse的内存分配的方法,通过修改Eclipse首选项中Java虚拟机的参数来解决的。可是究竟应该修改成多少,却有许多不同的说法。wKioL1XBsw3TAfbuAAMlV53n9Sg228.jpg

为此,仔细查看了eclipse-jee-luna-SR2-win32的readme_eclipse.html文档(位于安装路径下的readme文件夹中)。在文档的第4部分“Running Eclipse”中的“Allocating enough memory and solving OutOfMemoryErrors”部分给出了这个问题的答案:

By default, Eclipse will allocate up to 512 megabytes of Java heap memory. This should be ample for all typical development tasks. However, depending on the JRE that you are running, the number of additional plug-ins you are using, and the number of files you will be working with, you could conceivably have to increase this amount.  Eclipse allows you to pass arguments directly to the Java VM using the -vmargs command line argument, which must follow all other Eclipse specific arguments. Thus, to increase the available heap memory, you would typically use:

eclipse -vmargs -Xmx<memory size>

with the <memory size> value set to greater than "512M" (512 megabytes -- the default).

When using an Oracle VM below 1.8, you may also need to increase the size of the permanent generation memory.  The default maximum is 64 megabytes, but more may be needed depending on your plug-in configuration and use.  When the VM runs out of permanent generation memory, it may crash or hang during class loading. This failure is less common when using Oracle JRE version 1.5.0_07 or greater. The maximum permanent generation size is increased using the -XX:MaxPermSize=<memory size> argument:

eclipse -vmargs -XX:MaxPermSize=<memory size>

This argument may not be available for all VM versions and platforms; consult your VM documentation for more details.

Note that setting memory sizes to be larger than the amount of available physical memory on your machine will cause Java to "thrash" as it copies objects back and forth to virtual memory, which will severely degrade your performance.

受此启发,这次没再进入Eclipse环境去通过设置首选项来设置JVM的内存,而是创建了一个eclipse的快捷方式,在快捷方式中将缺省的D:\eclipse-jee-luna-SR2-win32\eclipse.exe修改为D:\eclipse-jee-luna-SR2-win32\eclipse.exe -vmargs -Xmx1024M并将开发环境中之前尝试过程中设置的JVM参数清空。

再次尝试,成功!