developer tip

Windows의 Maven 2에서 Java 힙 공간 설정

optionbox 2020. 9. 3. 08:20
반응형

Windows의 Maven 2에서 Java 힙 공간 설정


프로젝트를 빌드하는 동안이 메시지가 나타납니다.

java.lang.OutOfMemoryError : Java 힙 공간

힙 공간을 늘리려면 어떻게해야합니까? 8Gb 또는 RAM이있어 maven이 그렇게 많이 소비하는 것은 불가능합니다. http://vikashazrati.wordpress.com/2007/07/26/quicktip-how-to-increase-the -java-heap-memory-for-maven-2-on-linux / Linux 에서 수행하는 방법,하지만 Windows 7에 있습니다. Windows에서 Java 힙 공간을 어떻게 변경할 수 있습니까?


설정할 환경 변수는 MAVEN_OPTS예를 들어 MAVEN_OPTS=-Xmx1024m입니다. maxmempom 구성은 컴파일러 플러그인을 javac새 JVM 으로 포크하도록 설정 한 경우에만 적용됩니다 . 그렇지 않으면 플러그인은 Maven과 동일한 VM 내에서 실행되므로 명령 줄에서 MAVEN_OPTS.

Windows 7에서 MAVEN_OPTS를 설정하려면

  1. 내 컴퓨터를 마우스 오른쪽 버튼으로 클릭 하고 속성을 선택합니다 (키보드 단축키 Windows+를 누름 Pause/Break).
  2. 클릭 고급 시스템 설정은 디스플레이에 시스템 속성의 왼쪽 탐색에있는 링크하는 고급 시스템 등록 정보를
  3. 고급 탭으로 이동 하여 고급 시스템 속성 구성 창 하단에있는 환경 변수 버튼을 클릭 합니다.
  4. 크리에이트 새로운 사용자 변수의 설정 변수 이름을 MAVEN_OPTS로하고, 설정 변수 값 에을 -Xmx1024m(또는 그 이상)

새 명령 창을 열고 mvn.


확실한 (또는 비상 안전) JUnit 테스트 실행 중에 힙 공간이 부족한 경우 MAVEN_OPTS를 변경해도 도움이되지 않을 수 있습니다. 문제를 해결 한이 게시물찾을 때까지 나는 운없이 MAVEN_OPTS에서 다른 구성을 계속 시도했습니다 .

기본적으로 JUnits는 자체 환경으로 분기하고 MAVEN_OPTS의 설정을 무시합니다. JUnits에 더 많은 메모리를 추가하려면 pom에서 surefire를 구성해야합니다.

이로 인해 다른 사람이 시간을 절약 할 수 있기를 바랍니다.


편집 : 링크가 언젠가 끊어 질 경우를 대비하여 Keith Chapman의 블로그 에서 솔루션 복사 :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <forkMode>pertest</forkMode> 
    <argLine>-Xms256m -Xmx512m</argLine>
    <testFailureIgnore>false</testFailureIgnore> 
    <skip>false</skip> 
    <includes> 
      <include>**/*IntegrationTestSuite.java</include>
    </includes>
  </configuration>
</plugin>

업데이트 ( 2017 년 5 월 31 일 ) : 이 점을 지적 주신 @johnstosh 에게 감사드립니다 .이 답변을 발표 한 이후 확실하게 진화했습니다. 다음은 해당 문서에 대한 링크 와 업데이트 된 코드 샘플입니다 (인수 줄은 여전히이 질문에서 중요한 부분입니다).

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20</version>
    <configuration>
        <forkCount>3</forkCount>
        <reuseForks>true</reuseForks>
        <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
        <systemPropertyVariables>
            <databaseSchema>MY_TEST_SCHEMA_${surefire.forkNumber}</databaseSchema>
        </systemPropertyVariables>
        <workingDirectory>FORK_DIRECTORY_${surefire.forkNumber}</workingDirectory>
    </configuration>
  </plugin>

EXPORT 대신 SET을 제외하고 동일한 명령이어야합니다.

  • set MAVEN_OPTS = -Xmx512m은 512Mb의 힙을 제공합니다.
  • set MAVEN_OPTS = -Xmx2048m은 2Gb의 힙을 제공합니다.

Mac : JAVA_OPTS대신 MAVEN_OPTS_JAVA_OPTIONS를 사용하십시오. 작동합니다!


운없이 MAVEN_OPTS 변수를 사용하려고 시도한 후 저에게 도움 되는 사이트 를 발견했습니다. 그래서 내가해야 할 일은 기본 VM 옵션에 -Xms128m -Xmx1024m을 추가하는 것이 었습니다.

To change those in Eclipse, go to Window -> Preferences -> Java -> Installed JREs. Select the checked JRE/JDK and click edit.


On windows:

Add an environmental variable (in both system and user's variables, I have some weird problem, that it gets the var from various places, so I add them in both of them).

Name it MAVEN_OPTS.

Value will be: -Xms1024m -Xmx3000m -XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled

The numbers can be different, make them relative to your mem size.

I had that problem and this fixed it, nothing else!


It worked - To change in Eclipse, go to Window -> Preferences -> Java -> Installed JREs. Select the checked JRE/JDK and click edit.

Default VM Arguments = -Xms128m -Xmx1024m


You are looking for 2 options to java:

  • -Xmx maximum heap size
  • -Xms starting heap size

Put them in your command line invocation of the java executable, like this:

java -Xms512M -Xmx1024M my.package.MainClass

Keep in mind that you may want the starting and max heap sizes to be the same, depending on the application, as it avoids resizing the heap during runtime (which can take up time in applications that need to be responsive). Resizing the heap can entail moving a lot of objects around and redoing bookkeeping.

For every-day projects, make them whatever you think is good enough. Profile for help.

참고URL : https://stackoverflow.com/questions/2819853/setting-java-heap-space-under-maven-2-on-windows

반응형