Maven Out of Memory Build Failure












72















As of today, my maven compile fails.



[INFO] [ERROR] Unexpected
[INFO] java.lang.OutOfMemoryError: Java heap space
[INFO] at java.util.Arrays.copyOfRange(Arrays.java:2694)
[INFO] at java.lang.String.<init>(String.java:203)
[INFO] at java.lang.String.substring(String.java:1877)



[ERROR] Out of memory; to increase the amount of memory, use the -Xmx
flag at startup (java -Xmx128M ...)




As of yesterday I had successfully run a maven compile.



As of today, I just bumped up my heap to 3 GB. Also, I only changed 2-3 minor lines of code, so I don't understand this 'out of memory' error.



vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS
-Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m


EDIT: I tried the poster's comment by changing my failed module's pom.xml. But I got the same maven build error.



    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<meminitial>1024m</meminitial>
<maxmem>2024m</maxmem>
</configuration>
</plugin>









share|improve this question




















  • 1





    Could you provide more of the stacktrace? I'm curious to see what might be causing a String initialization to run out of memory. Setting heap size in MAVEN_OPTS sounds like the way to go but my guess is that somewhere there is a ridiculously large String that you might just not be allocating enough for -Xmx.

    – Edward Samson
    Sep 27 '12 at 6:24
















72















As of today, my maven compile fails.



[INFO] [ERROR] Unexpected
[INFO] java.lang.OutOfMemoryError: Java heap space
[INFO] at java.util.Arrays.copyOfRange(Arrays.java:2694)
[INFO] at java.lang.String.<init>(String.java:203)
[INFO] at java.lang.String.substring(String.java:1877)



[ERROR] Out of memory; to increase the amount of memory, use the -Xmx
flag at startup (java -Xmx128M ...)




As of yesterday I had successfully run a maven compile.



As of today, I just bumped up my heap to 3 GB. Also, I only changed 2-3 minor lines of code, so I don't understand this 'out of memory' error.



vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS
-Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m


EDIT: I tried the poster's comment by changing my failed module's pom.xml. But I got the same maven build error.



    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<meminitial>1024m</meminitial>
<maxmem>2024m</maxmem>
</configuration>
</plugin>









share|improve this question




















  • 1





    Could you provide more of the stacktrace? I'm curious to see what might be causing a String initialization to run out of memory. Setting heap size in MAVEN_OPTS sounds like the way to go but my guess is that somewhere there is a ridiculously large String that you might just not be allocating enough for -Xmx.

    – Edward Samson
    Sep 27 '12 at 6:24














72












72








72


18






As of today, my maven compile fails.



[INFO] [ERROR] Unexpected
[INFO] java.lang.OutOfMemoryError: Java heap space
[INFO] at java.util.Arrays.copyOfRange(Arrays.java:2694)
[INFO] at java.lang.String.<init>(String.java:203)
[INFO] at java.lang.String.substring(String.java:1877)



[ERROR] Out of memory; to increase the amount of memory, use the -Xmx
flag at startup (java -Xmx128M ...)




As of yesterday I had successfully run a maven compile.



As of today, I just bumped up my heap to 3 GB. Also, I only changed 2-3 minor lines of code, so I don't understand this 'out of memory' error.



vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS
-Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m


EDIT: I tried the poster's comment by changing my failed module's pom.xml. But I got the same maven build error.



    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<meminitial>1024m</meminitial>
<maxmem>2024m</maxmem>
</configuration>
</plugin>









share|improve this question
















As of today, my maven compile fails.



[INFO] [ERROR] Unexpected
[INFO] java.lang.OutOfMemoryError: Java heap space
[INFO] at java.util.Arrays.copyOfRange(Arrays.java:2694)
[INFO] at java.lang.String.<init>(String.java:203)
[INFO] at java.lang.String.substring(String.java:1877)



[ERROR] Out of memory; to increase the amount of memory, use the -Xmx
flag at startup (java -Xmx128M ...)




As of yesterday I had successfully run a maven compile.



As of today, I just bumped up my heap to 3 GB. Also, I only changed 2-3 minor lines of code, so I don't understand this 'out of memory' error.



vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS
-Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m


EDIT: I tried the poster's comment by changing my failed module's pom.xml. But I got the same maven build error.



    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<meminitial>1024m</meminitial>
<maxmem>2024m</maxmem>
</configuration>
</plugin>






maven out-of-memory maven-3 pom.xml maven-compiler-plugin






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 24 '18 at 19:04









A_Di-Matteo

17.7k65085




17.7k65085










asked Sep 19 '12 at 16:13









Kevin MeredithKevin Meredith

16.8k47141285




16.8k47141285








  • 1





    Could you provide more of the stacktrace? I'm curious to see what might be causing a String initialization to run out of memory. Setting heap size in MAVEN_OPTS sounds like the way to go but my guess is that somewhere there is a ridiculously large String that you might just not be allocating enough for -Xmx.

    – Edward Samson
    Sep 27 '12 at 6:24














  • 1





    Could you provide more of the stacktrace? I'm curious to see what might be causing a String initialization to run out of memory. Setting heap size in MAVEN_OPTS sounds like the way to go but my guess is that somewhere there is a ridiculously large String that you might just not be allocating enough for -Xmx.

    – Edward Samson
    Sep 27 '12 at 6:24








1




1





Could you provide more of the stacktrace? I'm curious to see what might be causing a String initialization to run out of memory. Setting heap size in MAVEN_OPTS sounds like the way to go but my guess is that somewhere there is a ridiculously large String that you might just not be allocating enough for -Xmx.

– Edward Samson
Sep 27 '12 at 6:24





Could you provide more of the stacktrace? I'm curious to see what might be causing a String initialization to run out of memory. Setting heap size in MAVEN_OPTS sounds like the way to go but my guess is that somewhere there is a ridiculously large String that you might just not be allocating enough for -Xmx.

– Edward Samson
Sep 27 '12 at 6:24












11 Answers
11






active

oldest

votes


















110





+75









What kind of 'web' module are you talking about?
Is it a simple war and has packaging type war?



If you are not using Google's web toolkit (GWT) then you don't need to offer any gwt.extraJvmArgs



Forking the compile process might be not the best idea because then you start a second process which ignores the MAVEN_OPTS at all and makes analysis more difficult.



So I would try to increase the Xmx by setting the MAVEN_OPTS



export MAVEN_OPTS="-Xmx3000m"


And don't fork the compiler to a different process



<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>


Increasing -XX:MaxPermSize=512m should not be required because if perm sice is the reason of the problem, then I would expect the error java.lang.OutOfMemoryError: PermGen space



If that does not solve your problem then you can create heap dumps for further analysis by adding -XX:+HeapDumpOnOutOfMemoryError. Additionally you can use jconsole.exe in you java's bin directory to connect to the jvm while the compilation is running and see what is going on inside the jvm's heap.



An other Idea (may be a stupid one) which came up to me, do you have enough RAM inside your machine? Defining the memory size is nice but if your host has only 4GB and then you might have the problem that Java is not able to use the defined Memory because it is already used by the OS, Java, MS-Office ... .






share|improve this answer
























  • thanks for your reply. Does your suggestion to remove the forked JVM also apply for the 'maven-surefire-plugin?' I tried your suggestion to bump up my MAVEN_OPTS memory to 3000. My maven-compiler did not have a setting for a forked JVM, so I did not need to change anything there. And yes, my Guest VM has 4 GB of RAM. The host machine has 8 GB RAM.

    – Kevin Meredith
    Sep 24 '12 at 12:43








  • 2





    by the way, the mvn build failed again with your suggestions.

    – Kevin Meredith
    Sep 24 '12 at 12:53






  • 1





    Usually I try to avoid process forking as long as I don't get it running. If your system has only 4GB then ~1 GB is used by OS. So you have 3GB rest. If maven starts with Xms=1GB then rest of free Memory is 2GB. Next the compiler fork started with Xms=1GB .... that reduces the free memory to 1GB. Now you can substract PermGen Memory 128MB, the forked failsafe-plugin process, ... As you can see your Xmx setting most probably could never be used be the JVM since the memory is simple not free. Have you tried using JConsole? and HeapDumpOnOutOfMemoryError?

    – vach
    Sep 24 '12 at 14:40













  • I removed the Xms1024m from my MAVEN_OPTS, yet the mvn build still failed. I added the "HeapDump..." to my MAVEN_OPTS, but I'm not sure where the dump gets printed. Looking into JConsole now.

    – Kevin Meredith
    Sep 24 '12 at 15:30











  • Dumps are plces in the jvms directory

    – vach
    Sep 24 '12 at 20:28



















24














Answering late to mention yet another option rather than the common MAVEN_OPTS environment variable to pass to the Maven build the required JVM options.



Since Maven 3.3.1, you could have an .mvn folder as part of the concerned project and a jvm.config file as perfect place for such an option.




two new optional configuration files .mvn/jvm.config and .mvn/maven.config, located at the base directory of project source tree. If present, these files will provide default jvm and maven options. Because these files are part of the project source tree, they will be present in all project checkouts and will be automatically used every time the project is build.




As part of the official release notes




In Maven it is not simple to define JVM configuration on a per project base. The existing mechanism based on an environment variable MAVEN_OPTS and the usage of ${user.home}/.mavenrc is an other option with the drawback of not being part of the project.



Starting with this release you can define JVM configuration via ${maven.projectBasedir}/.mvn/jvm.config file which means you can define the options for your build on a per project base. This file will become part of your project and will be checked in along with your project. So no need anymore for MAVEN_OPTS, .mavenrc files. So for example if you put the following JVM options into the ${maven.projectBasedir}/.mvn/jvm.config file:



-Xmx2048m -Xms1024m -XX:MaxPermSize=512m -Djava.awt.headless=true



The main advantage of this approach is that the configuration is isolated to the concerned project and applied to the whole build as well, and less fragile than MAVEN_OPTS for other developers working on the same project (forgetting to setting it).

Moreover, the options will be applied to all modules in case of a multi-module project.






share|improve this answer



















  • 1





    Nice feature I didn't know. It is really better for my big Jenkins project...

    – Karbos 538
    Feb 28 '18 at 8:44



















12














I got same problem trying to compile "clean install" using a Lowend 512Mb ram VPS and good CPU. Run OutOfMemory and killed script repeatly.



I used export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=350m" and worked.



Still getting some other compiling failure because is the first time i need Maven, but OutOfMemory problem has gone.






share|improve this answer































    10














    Add option



    -XX:MaxPermSize=512m


    to MAVEN_OPTS



    maven-compiler-plugin options



      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
    <fork>true</fork>
    <meminitial>1024m</meminitial>
    <maxmem>2024m</maxmem>
    </configuration>
    </plugin>





    share|improve this answer





















    • 1





      I actually added the option, -XX:MaxPermSize=1024m, after making this post. But I still got an out of memory error. Another SO post mentioned that I need to add an option to maven-surefire-plugin's argLine to bump up the memory used by forked threads. I increased it to <argLine>-Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m</argLine>

      – Kevin Meredith
      Sep 19 '12 at 17:08











    • And it was helpful?

      – Ilya
      Sep 19 '12 at 17:09











    • I should've mentioned that... No, the maven build still failed.

      – Kevin Meredith
      Sep 19 '12 at 17:13











    • any other ideas? bump...

      – Kevin Meredith
      Sep 20 '12 at 12:37













    • Add all this properties to maven-compilier-plugin and increase -XX:MaxPermSize, Xmx should be = XX:MaxPermSize

      – Ilya
      Sep 20 '12 at 16:18





















    3














    What type of OS are you running on?



    In order to assign more than 2GB of ram it needs to be at least a 64bit OS.



    Then there is another problem. Even if your OS has Unlimited RAM, but that is fragmented in a way that not a single free block of 2GB is available, you'll get out of memory exceptions too. And keep in mind that the normal Heap memory is only part of the memory the VM process is using. So on a 32bit machine you will probably never be able to set Xmx to 2048MB.



    I would also suggest to set min an max memory to the same value, because in this case as soon as the VM runs out of memory the frist time 1GB is allocated from the start, the VM then allocates a new block (assuming it increases with 500MB blocks) of 1,5GB after that is allocated, it would copy all the stuff from block one to the new one and free Memory after that. If it runs out of Memory again the 2GB are allocated and the 1,5 GB are then copied, temporarily allocating 3,5GB of memory.






    share|improve this answer































      2














      I got same problem when compiling Druid.io, increasing the MaxDirectMemorySize finally worked.



      export MAVEN_OPTS="-Xms8g -Xmx8g -XX:MaxDirectMemorySize=4096m"





      share|improve this answer
























      • Curious, MaxDirectMemorySize is ostensibly unbounded by default (i.e. you added a limit, not adjusted a preexisting one).

        – Tomer Gabel
        Jun 18 '17 at 11:04



















      1














      _JAVA_OPTIONS="-Xmx3G" mvn clean install





      share|improve this answer

































        0














        Using .mvn/jvm.config worked for me plus has the added benefit of being linked with the project.






        share|improve this answer































          0














          This below configuration working in my case



          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>${maven-surefire-plugin.version}</version>
          <configuration>
          <verbose>true</verbose>
          <fork>true</fork>
          <argLine>-XX:MaxPermSize=500M</argLine>
          </configuration>
          </plugin>


          Try to use -XX:MaxPermSize instead of -XX:MaxPermGen






          share|improve this answer

































            0














            While building the project on Unix/Linux platform, set Maven options syntax as below. Notice that single qoutation signs, not double qoutation.



            export MAVEN_OPTS='-Xmx512m -XX:MaxPermSize=128m'





            share|improve this answer































              0














              This happens in big projects on Windows when cygwin or other linux emulator is used(git bash). By some coincidence, both does not work on my project, what is an big open source project. In a sh script, a couple of mvn commands are called. The memory size grows to heap size bigger that specified in Xmx and most of the time in a case second windows process is started. This is making the memory consumption even higher.



              The solution in this case is to use batch file and reduced Xmx size and then the maven operations are successful. If there is interest I can reveal more details.






              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12498738%2fmaven-out-of-memory-build-failure%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                11 Answers
                11






                active

                oldest

                votes








                11 Answers
                11






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                110





                +75









                What kind of 'web' module are you talking about?
                Is it a simple war and has packaging type war?



                If you are not using Google's web toolkit (GWT) then you don't need to offer any gwt.extraJvmArgs



                Forking the compile process might be not the best idea because then you start a second process which ignores the MAVEN_OPTS at all and makes analysis more difficult.



                So I would try to increase the Xmx by setting the MAVEN_OPTS



                export MAVEN_OPTS="-Xmx3000m"


                And don't fork the compiler to a different process



                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                <source>1.5</source>
                <target>1.5</target>
                </configuration>
                </plugin>


                Increasing -XX:MaxPermSize=512m should not be required because if perm sice is the reason of the problem, then I would expect the error java.lang.OutOfMemoryError: PermGen space



                If that does not solve your problem then you can create heap dumps for further analysis by adding -XX:+HeapDumpOnOutOfMemoryError. Additionally you can use jconsole.exe in you java's bin directory to connect to the jvm while the compilation is running and see what is going on inside the jvm's heap.



                An other Idea (may be a stupid one) which came up to me, do you have enough RAM inside your machine? Defining the memory size is nice but if your host has only 4GB and then you might have the problem that Java is not able to use the defined Memory because it is already used by the OS, Java, MS-Office ... .






                share|improve this answer
























                • thanks for your reply. Does your suggestion to remove the forked JVM also apply for the 'maven-surefire-plugin?' I tried your suggestion to bump up my MAVEN_OPTS memory to 3000. My maven-compiler did not have a setting for a forked JVM, so I did not need to change anything there. And yes, my Guest VM has 4 GB of RAM. The host machine has 8 GB RAM.

                  – Kevin Meredith
                  Sep 24 '12 at 12:43








                • 2





                  by the way, the mvn build failed again with your suggestions.

                  – Kevin Meredith
                  Sep 24 '12 at 12:53






                • 1





                  Usually I try to avoid process forking as long as I don't get it running. If your system has only 4GB then ~1 GB is used by OS. So you have 3GB rest. If maven starts with Xms=1GB then rest of free Memory is 2GB. Next the compiler fork started with Xms=1GB .... that reduces the free memory to 1GB. Now you can substract PermGen Memory 128MB, the forked failsafe-plugin process, ... As you can see your Xmx setting most probably could never be used be the JVM since the memory is simple not free. Have you tried using JConsole? and HeapDumpOnOutOfMemoryError?

                  – vach
                  Sep 24 '12 at 14:40













                • I removed the Xms1024m from my MAVEN_OPTS, yet the mvn build still failed. I added the "HeapDump..." to my MAVEN_OPTS, but I'm not sure where the dump gets printed. Looking into JConsole now.

                  – Kevin Meredith
                  Sep 24 '12 at 15:30











                • Dumps are plces in the jvms directory

                  – vach
                  Sep 24 '12 at 20:28
















                110





                +75









                What kind of 'web' module are you talking about?
                Is it a simple war and has packaging type war?



                If you are not using Google's web toolkit (GWT) then you don't need to offer any gwt.extraJvmArgs



                Forking the compile process might be not the best idea because then you start a second process which ignores the MAVEN_OPTS at all and makes analysis more difficult.



                So I would try to increase the Xmx by setting the MAVEN_OPTS



                export MAVEN_OPTS="-Xmx3000m"


                And don't fork the compiler to a different process



                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                <source>1.5</source>
                <target>1.5</target>
                </configuration>
                </plugin>


                Increasing -XX:MaxPermSize=512m should not be required because if perm sice is the reason of the problem, then I would expect the error java.lang.OutOfMemoryError: PermGen space



                If that does not solve your problem then you can create heap dumps for further analysis by adding -XX:+HeapDumpOnOutOfMemoryError. Additionally you can use jconsole.exe in you java's bin directory to connect to the jvm while the compilation is running and see what is going on inside the jvm's heap.



                An other Idea (may be a stupid one) which came up to me, do you have enough RAM inside your machine? Defining the memory size is nice but if your host has only 4GB and then you might have the problem that Java is not able to use the defined Memory because it is already used by the OS, Java, MS-Office ... .






                share|improve this answer
























                • thanks for your reply. Does your suggestion to remove the forked JVM also apply for the 'maven-surefire-plugin?' I tried your suggestion to bump up my MAVEN_OPTS memory to 3000. My maven-compiler did not have a setting for a forked JVM, so I did not need to change anything there. And yes, my Guest VM has 4 GB of RAM. The host machine has 8 GB RAM.

                  – Kevin Meredith
                  Sep 24 '12 at 12:43








                • 2





                  by the way, the mvn build failed again with your suggestions.

                  – Kevin Meredith
                  Sep 24 '12 at 12:53






                • 1





                  Usually I try to avoid process forking as long as I don't get it running. If your system has only 4GB then ~1 GB is used by OS. So you have 3GB rest. If maven starts with Xms=1GB then rest of free Memory is 2GB. Next the compiler fork started with Xms=1GB .... that reduces the free memory to 1GB. Now you can substract PermGen Memory 128MB, the forked failsafe-plugin process, ... As you can see your Xmx setting most probably could never be used be the JVM since the memory is simple not free. Have you tried using JConsole? and HeapDumpOnOutOfMemoryError?

                  – vach
                  Sep 24 '12 at 14:40













                • I removed the Xms1024m from my MAVEN_OPTS, yet the mvn build still failed. I added the "HeapDump..." to my MAVEN_OPTS, but I'm not sure where the dump gets printed. Looking into JConsole now.

                  – Kevin Meredith
                  Sep 24 '12 at 15:30











                • Dumps are plces in the jvms directory

                  – vach
                  Sep 24 '12 at 20:28














                110





                +75







                110





                +75



                110




                +75





                What kind of 'web' module are you talking about?
                Is it a simple war and has packaging type war?



                If you are not using Google's web toolkit (GWT) then you don't need to offer any gwt.extraJvmArgs



                Forking the compile process might be not the best idea because then you start a second process which ignores the MAVEN_OPTS at all and makes analysis more difficult.



                So I would try to increase the Xmx by setting the MAVEN_OPTS



                export MAVEN_OPTS="-Xmx3000m"


                And don't fork the compiler to a different process



                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                <source>1.5</source>
                <target>1.5</target>
                </configuration>
                </plugin>


                Increasing -XX:MaxPermSize=512m should not be required because if perm sice is the reason of the problem, then I would expect the error java.lang.OutOfMemoryError: PermGen space



                If that does not solve your problem then you can create heap dumps for further analysis by adding -XX:+HeapDumpOnOutOfMemoryError. Additionally you can use jconsole.exe in you java's bin directory to connect to the jvm while the compilation is running and see what is going on inside the jvm's heap.



                An other Idea (may be a stupid one) which came up to me, do you have enough RAM inside your machine? Defining the memory size is nice but if your host has only 4GB and then you might have the problem that Java is not able to use the defined Memory because it is already used by the OS, Java, MS-Office ... .






                share|improve this answer













                What kind of 'web' module are you talking about?
                Is it a simple war and has packaging type war?



                If you are not using Google's web toolkit (GWT) then you don't need to offer any gwt.extraJvmArgs



                Forking the compile process might be not the best idea because then you start a second process which ignores the MAVEN_OPTS at all and makes analysis more difficult.



                So I would try to increase the Xmx by setting the MAVEN_OPTS



                export MAVEN_OPTS="-Xmx3000m"


                And don't fork the compiler to a different process



                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                <source>1.5</source>
                <target>1.5</target>
                </configuration>
                </plugin>


                Increasing -XX:MaxPermSize=512m should not be required because if perm sice is the reason of the problem, then I would expect the error java.lang.OutOfMemoryError: PermGen space



                If that does not solve your problem then you can create heap dumps for further analysis by adding -XX:+HeapDumpOnOutOfMemoryError. Additionally you can use jconsole.exe in you java's bin directory to connect to the jvm while the compilation is running and see what is going on inside the jvm's heap.



                An other Idea (may be a stupid one) which came up to me, do you have enough RAM inside your machine? Defining the memory size is nice but if your host has only 4GB and then you might have the problem that Java is not able to use the defined Memory because it is already used by the OS, Java, MS-Office ... .







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 22 '12 at 12:56









                vachvach

                1,315187




                1,315187













                • thanks for your reply. Does your suggestion to remove the forked JVM also apply for the 'maven-surefire-plugin?' I tried your suggestion to bump up my MAVEN_OPTS memory to 3000. My maven-compiler did not have a setting for a forked JVM, so I did not need to change anything there. And yes, my Guest VM has 4 GB of RAM. The host machine has 8 GB RAM.

                  – Kevin Meredith
                  Sep 24 '12 at 12:43








                • 2





                  by the way, the mvn build failed again with your suggestions.

                  – Kevin Meredith
                  Sep 24 '12 at 12:53






                • 1





                  Usually I try to avoid process forking as long as I don't get it running. If your system has only 4GB then ~1 GB is used by OS. So you have 3GB rest. If maven starts with Xms=1GB then rest of free Memory is 2GB. Next the compiler fork started with Xms=1GB .... that reduces the free memory to 1GB. Now you can substract PermGen Memory 128MB, the forked failsafe-plugin process, ... As you can see your Xmx setting most probably could never be used be the JVM since the memory is simple not free. Have you tried using JConsole? and HeapDumpOnOutOfMemoryError?

                  – vach
                  Sep 24 '12 at 14:40













                • I removed the Xms1024m from my MAVEN_OPTS, yet the mvn build still failed. I added the "HeapDump..." to my MAVEN_OPTS, but I'm not sure where the dump gets printed. Looking into JConsole now.

                  – Kevin Meredith
                  Sep 24 '12 at 15:30











                • Dumps are plces in the jvms directory

                  – vach
                  Sep 24 '12 at 20:28



















                • thanks for your reply. Does your suggestion to remove the forked JVM also apply for the 'maven-surefire-plugin?' I tried your suggestion to bump up my MAVEN_OPTS memory to 3000. My maven-compiler did not have a setting for a forked JVM, so I did not need to change anything there. And yes, my Guest VM has 4 GB of RAM. The host machine has 8 GB RAM.

                  – Kevin Meredith
                  Sep 24 '12 at 12:43








                • 2





                  by the way, the mvn build failed again with your suggestions.

                  – Kevin Meredith
                  Sep 24 '12 at 12:53






                • 1





                  Usually I try to avoid process forking as long as I don't get it running. If your system has only 4GB then ~1 GB is used by OS. So you have 3GB rest. If maven starts with Xms=1GB then rest of free Memory is 2GB. Next the compiler fork started with Xms=1GB .... that reduces the free memory to 1GB. Now you can substract PermGen Memory 128MB, the forked failsafe-plugin process, ... As you can see your Xmx setting most probably could never be used be the JVM since the memory is simple not free. Have you tried using JConsole? and HeapDumpOnOutOfMemoryError?

                  – vach
                  Sep 24 '12 at 14:40













                • I removed the Xms1024m from my MAVEN_OPTS, yet the mvn build still failed. I added the "HeapDump..." to my MAVEN_OPTS, but I'm not sure where the dump gets printed. Looking into JConsole now.

                  – Kevin Meredith
                  Sep 24 '12 at 15:30











                • Dumps are plces in the jvms directory

                  – vach
                  Sep 24 '12 at 20:28

















                thanks for your reply. Does your suggestion to remove the forked JVM also apply for the 'maven-surefire-plugin?' I tried your suggestion to bump up my MAVEN_OPTS memory to 3000. My maven-compiler did not have a setting for a forked JVM, so I did not need to change anything there. And yes, my Guest VM has 4 GB of RAM. The host machine has 8 GB RAM.

                – Kevin Meredith
                Sep 24 '12 at 12:43







                thanks for your reply. Does your suggestion to remove the forked JVM also apply for the 'maven-surefire-plugin?' I tried your suggestion to bump up my MAVEN_OPTS memory to 3000. My maven-compiler did not have a setting for a forked JVM, so I did not need to change anything there. And yes, my Guest VM has 4 GB of RAM. The host machine has 8 GB RAM.

                – Kevin Meredith
                Sep 24 '12 at 12:43






                2




                2





                by the way, the mvn build failed again with your suggestions.

                – Kevin Meredith
                Sep 24 '12 at 12:53





                by the way, the mvn build failed again with your suggestions.

                – Kevin Meredith
                Sep 24 '12 at 12:53




                1




                1





                Usually I try to avoid process forking as long as I don't get it running. If your system has only 4GB then ~1 GB is used by OS. So you have 3GB rest. If maven starts with Xms=1GB then rest of free Memory is 2GB. Next the compiler fork started with Xms=1GB .... that reduces the free memory to 1GB. Now you can substract PermGen Memory 128MB, the forked failsafe-plugin process, ... As you can see your Xmx setting most probably could never be used be the JVM since the memory is simple not free. Have you tried using JConsole? and HeapDumpOnOutOfMemoryError?

                – vach
                Sep 24 '12 at 14:40







                Usually I try to avoid process forking as long as I don't get it running. If your system has only 4GB then ~1 GB is used by OS. So you have 3GB rest. If maven starts with Xms=1GB then rest of free Memory is 2GB. Next the compiler fork started with Xms=1GB .... that reduces the free memory to 1GB. Now you can substract PermGen Memory 128MB, the forked failsafe-plugin process, ... As you can see your Xmx setting most probably could never be used be the JVM since the memory is simple not free. Have you tried using JConsole? and HeapDumpOnOutOfMemoryError?

                – vach
                Sep 24 '12 at 14:40















                I removed the Xms1024m from my MAVEN_OPTS, yet the mvn build still failed. I added the "HeapDump..." to my MAVEN_OPTS, but I'm not sure where the dump gets printed. Looking into JConsole now.

                – Kevin Meredith
                Sep 24 '12 at 15:30





                I removed the Xms1024m from my MAVEN_OPTS, yet the mvn build still failed. I added the "HeapDump..." to my MAVEN_OPTS, but I'm not sure where the dump gets printed. Looking into JConsole now.

                – Kevin Meredith
                Sep 24 '12 at 15:30













                Dumps are plces in the jvms directory

                – vach
                Sep 24 '12 at 20:28





                Dumps are plces in the jvms directory

                – vach
                Sep 24 '12 at 20:28













                24














                Answering late to mention yet another option rather than the common MAVEN_OPTS environment variable to pass to the Maven build the required JVM options.



                Since Maven 3.3.1, you could have an .mvn folder as part of the concerned project and a jvm.config file as perfect place for such an option.




                two new optional configuration files .mvn/jvm.config and .mvn/maven.config, located at the base directory of project source tree. If present, these files will provide default jvm and maven options. Because these files are part of the project source tree, they will be present in all project checkouts and will be automatically used every time the project is build.




                As part of the official release notes




                In Maven it is not simple to define JVM configuration on a per project base. The existing mechanism based on an environment variable MAVEN_OPTS and the usage of ${user.home}/.mavenrc is an other option with the drawback of not being part of the project.



                Starting with this release you can define JVM configuration via ${maven.projectBasedir}/.mvn/jvm.config file which means you can define the options for your build on a per project base. This file will become part of your project and will be checked in along with your project. So no need anymore for MAVEN_OPTS, .mavenrc files. So for example if you put the following JVM options into the ${maven.projectBasedir}/.mvn/jvm.config file:



                -Xmx2048m -Xms1024m -XX:MaxPermSize=512m -Djava.awt.headless=true



                The main advantage of this approach is that the configuration is isolated to the concerned project and applied to the whole build as well, and less fragile than MAVEN_OPTS for other developers working on the same project (forgetting to setting it).

                Moreover, the options will be applied to all modules in case of a multi-module project.






                share|improve this answer



















                • 1





                  Nice feature I didn't know. It is really better for my big Jenkins project...

                  – Karbos 538
                  Feb 28 '18 at 8:44
















                24














                Answering late to mention yet another option rather than the common MAVEN_OPTS environment variable to pass to the Maven build the required JVM options.



                Since Maven 3.3.1, you could have an .mvn folder as part of the concerned project and a jvm.config file as perfect place for such an option.




                two new optional configuration files .mvn/jvm.config and .mvn/maven.config, located at the base directory of project source tree. If present, these files will provide default jvm and maven options. Because these files are part of the project source tree, they will be present in all project checkouts and will be automatically used every time the project is build.




                As part of the official release notes




                In Maven it is not simple to define JVM configuration on a per project base. The existing mechanism based on an environment variable MAVEN_OPTS and the usage of ${user.home}/.mavenrc is an other option with the drawback of not being part of the project.



                Starting with this release you can define JVM configuration via ${maven.projectBasedir}/.mvn/jvm.config file which means you can define the options for your build on a per project base. This file will become part of your project and will be checked in along with your project. So no need anymore for MAVEN_OPTS, .mavenrc files. So for example if you put the following JVM options into the ${maven.projectBasedir}/.mvn/jvm.config file:



                -Xmx2048m -Xms1024m -XX:MaxPermSize=512m -Djava.awt.headless=true



                The main advantage of this approach is that the configuration is isolated to the concerned project and applied to the whole build as well, and less fragile than MAVEN_OPTS for other developers working on the same project (forgetting to setting it).

                Moreover, the options will be applied to all modules in case of a multi-module project.






                share|improve this answer



















                • 1





                  Nice feature I didn't know. It is really better for my big Jenkins project...

                  – Karbos 538
                  Feb 28 '18 at 8:44














                24












                24








                24







                Answering late to mention yet another option rather than the common MAVEN_OPTS environment variable to pass to the Maven build the required JVM options.



                Since Maven 3.3.1, you could have an .mvn folder as part of the concerned project and a jvm.config file as perfect place for such an option.




                two new optional configuration files .mvn/jvm.config and .mvn/maven.config, located at the base directory of project source tree. If present, these files will provide default jvm and maven options. Because these files are part of the project source tree, they will be present in all project checkouts and will be automatically used every time the project is build.




                As part of the official release notes




                In Maven it is not simple to define JVM configuration on a per project base. The existing mechanism based on an environment variable MAVEN_OPTS and the usage of ${user.home}/.mavenrc is an other option with the drawback of not being part of the project.



                Starting with this release you can define JVM configuration via ${maven.projectBasedir}/.mvn/jvm.config file which means you can define the options for your build on a per project base. This file will become part of your project and will be checked in along with your project. So no need anymore for MAVEN_OPTS, .mavenrc files. So for example if you put the following JVM options into the ${maven.projectBasedir}/.mvn/jvm.config file:



                -Xmx2048m -Xms1024m -XX:MaxPermSize=512m -Djava.awt.headless=true



                The main advantage of this approach is that the configuration is isolated to the concerned project and applied to the whole build as well, and less fragile than MAVEN_OPTS for other developers working on the same project (forgetting to setting it).

                Moreover, the options will be applied to all modules in case of a multi-module project.






                share|improve this answer













                Answering late to mention yet another option rather than the common MAVEN_OPTS environment variable to pass to the Maven build the required JVM options.



                Since Maven 3.3.1, you could have an .mvn folder as part of the concerned project and a jvm.config file as perfect place for such an option.




                two new optional configuration files .mvn/jvm.config and .mvn/maven.config, located at the base directory of project source tree. If present, these files will provide default jvm and maven options. Because these files are part of the project source tree, they will be present in all project checkouts and will be automatically used every time the project is build.




                As part of the official release notes




                In Maven it is not simple to define JVM configuration on a per project base. The existing mechanism based on an environment variable MAVEN_OPTS and the usage of ${user.home}/.mavenrc is an other option with the drawback of not being part of the project.



                Starting with this release you can define JVM configuration via ${maven.projectBasedir}/.mvn/jvm.config file which means you can define the options for your build on a per project base. This file will become part of your project and will be checked in along with your project. So no need anymore for MAVEN_OPTS, .mavenrc files. So for example if you put the following JVM options into the ${maven.projectBasedir}/.mvn/jvm.config file:



                -Xmx2048m -Xms1024m -XX:MaxPermSize=512m -Djava.awt.headless=true



                The main advantage of this approach is that the configuration is isolated to the concerned project and applied to the whole build as well, and less fragile than MAVEN_OPTS for other developers working on the same project (forgetting to setting it).

                Moreover, the options will be applied to all modules in case of a multi-module project.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 14 '16 at 21:50









                A_Di-MatteoA_Di-Matteo

                17.7k65085




                17.7k65085








                • 1





                  Nice feature I didn't know. It is really better for my big Jenkins project...

                  – Karbos 538
                  Feb 28 '18 at 8:44














                • 1





                  Nice feature I didn't know. It is really better for my big Jenkins project...

                  – Karbos 538
                  Feb 28 '18 at 8:44








                1




                1





                Nice feature I didn't know. It is really better for my big Jenkins project...

                – Karbos 538
                Feb 28 '18 at 8:44





                Nice feature I didn't know. It is really better for my big Jenkins project...

                – Karbos 538
                Feb 28 '18 at 8:44











                12














                I got same problem trying to compile "clean install" using a Lowend 512Mb ram VPS and good CPU. Run OutOfMemory and killed script repeatly.



                I used export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=350m" and worked.



                Still getting some other compiling failure because is the first time i need Maven, but OutOfMemory problem has gone.






                share|improve this answer




























                  12














                  I got same problem trying to compile "clean install" using a Lowend 512Mb ram VPS and good CPU. Run OutOfMemory and killed script repeatly.



                  I used export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=350m" and worked.



                  Still getting some other compiling failure because is the first time i need Maven, but OutOfMemory problem has gone.






                  share|improve this answer


























                    12












                    12








                    12







                    I got same problem trying to compile "clean install" using a Lowend 512Mb ram VPS and good CPU. Run OutOfMemory and killed script repeatly.



                    I used export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=350m" and worked.



                    Still getting some other compiling failure because is the first time i need Maven, but OutOfMemory problem has gone.






                    share|improve this answer













                    I got same problem trying to compile "clean install" using a Lowend 512Mb ram VPS and good CPU. Run OutOfMemory and killed script repeatly.



                    I used export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=350m" and worked.



                    Still getting some other compiling failure because is the first time i need Maven, but OutOfMemory problem has gone.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 19 '15 at 6:06









                    erm3ndaerm3nda

                    1,2601535




                    1,2601535























                        10














                        Add option



                        -XX:MaxPermSize=512m


                        to MAVEN_OPTS



                        maven-compiler-plugin options



                          <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                        <fork>true</fork>
                        <meminitial>1024m</meminitial>
                        <maxmem>2024m</maxmem>
                        </configuration>
                        </plugin>





                        share|improve this answer





















                        • 1





                          I actually added the option, -XX:MaxPermSize=1024m, after making this post. But I still got an out of memory error. Another SO post mentioned that I need to add an option to maven-surefire-plugin's argLine to bump up the memory used by forked threads. I increased it to <argLine>-Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m</argLine>

                          – Kevin Meredith
                          Sep 19 '12 at 17:08











                        • And it was helpful?

                          – Ilya
                          Sep 19 '12 at 17:09











                        • I should've mentioned that... No, the maven build still failed.

                          – Kevin Meredith
                          Sep 19 '12 at 17:13











                        • any other ideas? bump...

                          – Kevin Meredith
                          Sep 20 '12 at 12:37













                        • Add all this properties to maven-compilier-plugin and increase -XX:MaxPermSize, Xmx should be = XX:MaxPermSize

                          – Ilya
                          Sep 20 '12 at 16:18


















                        10














                        Add option



                        -XX:MaxPermSize=512m


                        to MAVEN_OPTS



                        maven-compiler-plugin options



                          <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                        <fork>true</fork>
                        <meminitial>1024m</meminitial>
                        <maxmem>2024m</maxmem>
                        </configuration>
                        </plugin>





                        share|improve this answer





















                        • 1





                          I actually added the option, -XX:MaxPermSize=1024m, after making this post. But I still got an out of memory error. Another SO post mentioned that I need to add an option to maven-surefire-plugin's argLine to bump up the memory used by forked threads. I increased it to <argLine>-Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m</argLine>

                          – Kevin Meredith
                          Sep 19 '12 at 17:08











                        • And it was helpful?

                          – Ilya
                          Sep 19 '12 at 17:09











                        • I should've mentioned that... No, the maven build still failed.

                          – Kevin Meredith
                          Sep 19 '12 at 17:13











                        • any other ideas? bump...

                          – Kevin Meredith
                          Sep 20 '12 at 12:37













                        • Add all this properties to maven-compilier-plugin and increase -XX:MaxPermSize, Xmx should be = XX:MaxPermSize

                          – Ilya
                          Sep 20 '12 at 16:18
















                        10












                        10








                        10







                        Add option



                        -XX:MaxPermSize=512m


                        to MAVEN_OPTS



                        maven-compiler-plugin options



                          <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                        <fork>true</fork>
                        <meminitial>1024m</meminitial>
                        <maxmem>2024m</maxmem>
                        </configuration>
                        </plugin>





                        share|improve this answer















                        Add option



                        -XX:MaxPermSize=512m


                        to MAVEN_OPTS



                        maven-compiler-plugin options



                          <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                        <fork>true</fork>
                        <meminitial>1024m</meminitial>
                        <maxmem>2024m</maxmem>
                        </configuration>
                        </plugin>






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Sep 20 '12 at 16:27

























                        answered Sep 19 '12 at 16:50









                        IlyaIlya

                        23.3k1891141




                        23.3k1891141








                        • 1





                          I actually added the option, -XX:MaxPermSize=1024m, after making this post. But I still got an out of memory error. Another SO post mentioned that I need to add an option to maven-surefire-plugin's argLine to bump up the memory used by forked threads. I increased it to <argLine>-Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m</argLine>

                          – Kevin Meredith
                          Sep 19 '12 at 17:08











                        • And it was helpful?

                          – Ilya
                          Sep 19 '12 at 17:09











                        • I should've mentioned that... No, the maven build still failed.

                          – Kevin Meredith
                          Sep 19 '12 at 17:13











                        • any other ideas? bump...

                          – Kevin Meredith
                          Sep 20 '12 at 12:37













                        • Add all this properties to maven-compilier-plugin and increase -XX:MaxPermSize, Xmx should be = XX:MaxPermSize

                          – Ilya
                          Sep 20 '12 at 16:18
















                        • 1





                          I actually added the option, -XX:MaxPermSize=1024m, after making this post. But I still got an out of memory error. Another SO post mentioned that I need to add an option to maven-surefire-plugin's argLine to bump up the memory used by forked threads. I increased it to <argLine>-Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m</argLine>

                          – Kevin Meredith
                          Sep 19 '12 at 17:08











                        • And it was helpful?

                          – Ilya
                          Sep 19 '12 at 17:09











                        • I should've mentioned that... No, the maven build still failed.

                          – Kevin Meredith
                          Sep 19 '12 at 17:13











                        • any other ideas? bump...

                          – Kevin Meredith
                          Sep 20 '12 at 12:37













                        • Add all this properties to maven-compilier-plugin and increase -XX:MaxPermSize, Xmx should be = XX:MaxPermSize

                          – Ilya
                          Sep 20 '12 at 16:18










                        1




                        1





                        I actually added the option, -XX:MaxPermSize=1024m, after making this post. But I still got an out of memory error. Another SO post mentioned that I need to add an option to maven-surefire-plugin's argLine to bump up the memory used by forked threads. I increased it to <argLine>-Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m</argLine>

                        – Kevin Meredith
                        Sep 19 '12 at 17:08





                        I actually added the option, -XX:MaxPermSize=1024m, after making this post. But I still got an out of memory error. Another SO post mentioned that I need to add an option to maven-surefire-plugin's argLine to bump up the memory used by forked threads. I increased it to <argLine>-Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m</argLine>

                        – Kevin Meredith
                        Sep 19 '12 at 17:08













                        And it was helpful?

                        – Ilya
                        Sep 19 '12 at 17:09





                        And it was helpful?

                        – Ilya
                        Sep 19 '12 at 17:09













                        I should've mentioned that... No, the maven build still failed.

                        – Kevin Meredith
                        Sep 19 '12 at 17:13





                        I should've mentioned that... No, the maven build still failed.

                        – Kevin Meredith
                        Sep 19 '12 at 17:13













                        any other ideas? bump...

                        – Kevin Meredith
                        Sep 20 '12 at 12:37







                        any other ideas? bump...

                        – Kevin Meredith
                        Sep 20 '12 at 12:37















                        Add all this properties to maven-compilier-plugin and increase -XX:MaxPermSize, Xmx should be = XX:MaxPermSize

                        – Ilya
                        Sep 20 '12 at 16:18







                        Add all this properties to maven-compilier-plugin and increase -XX:MaxPermSize, Xmx should be = XX:MaxPermSize

                        – Ilya
                        Sep 20 '12 at 16:18













                        3














                        What type of OS are you running on?



                        In order to assign more than 2GB of ram it needs to be at least a 64bit OS.



                        Then there is another problem. Even if your OS has Unlimited RAM, but that is fragmented in a way that not a single free block of 2GB is available, you'll get out of memory exceptions too. And keep in mind that the normal Heap memory is only part of the memory the VM process is using. So on a 32bit machine you will probably never be able to set Xmx to 2048MB.



                        I would also suggest to set min an max memory to the same value, because in this case as soon as the VM runs out of memory the frist time 1GB is allocated from the start, the VM then allocates a new block (assuming it increases with 500MB blocks) of 1,5GB after that is allocated, it would copy all the stuff from block one to the new one and free Memory after that. If it runs out of Memory again the 2GB are allocated and the 1,5 GB are then copied, temporarily allocating 3,5GB of memory.






                        share|improve this answer




























                          3














                          What type of OS are you running on?



                          In order to assign more than 2GB of ram it needs to be at least a 64bit OS.



                          Then there is another problem. Even if your OS has Unlimited RAM, but that is fragmented in a way that not a single free block of 2GB is available, you'll get out of memory exceptions too. And keep in mind that the normal Heap memory is only part of the memory the VM process is using. So on a 32bit machine you will probably never be able to set Xmx to 2048MB.



                          I would also suggest to set min an max memory to the same value, because in this case as soon as the VM runs out of memory the frist time 1GB is allocated from the start, the VM then allocates a new block (assuming it increases with 500MB blocks) of 1,5GB after that is allocated, it would copy all the stuff from block one to the new one and free Memory after that. If it runs out of Memory again the 2GB are allocated and the 1,5 GB are then copied, temporarily allocating 3,5GB of memory.






                          share|improve this answer


























                            3












                            3








                            3







                            What type of OS are you running on?



                            In order to assign more than 2GB of ram it needs to be at least a 64bit OS.



                            Then there is another problem. Even if your OS has Unlimited RAM, but that is fragmented in a way that not a single free block of 2GB is available, you'll get out of memory exceptions too. And keep in mind that the normal Heap memory is only part of the memory the VM process is using. So on a 32bit machine you will probably never be able to set Xmx to 2048MB.



                            I would also suggest to set min an max memory to the same value, because in this case as soon as the VM runs out of memory the frist time 1GB is allocated from the start, the VM then allocates a new block (assuming it increases with 500MB blocks) of 1,5GB after that is allocated, it would copy all the stuff from block one to the new one and free Memory after that. If it runs out of Memory again the 2GB are allocated and the 1,5 GB are then copied, temporarily allocating 3,5GB of memory.






                            share|improve this answer













                            What type of OS are you running on?



                            In order to assign more than 2GB of ram it needs to be at least a 64bit OS.



                            Then there is another problem. Even if your OS has Unlimited RAM, but that is fragmented in a way that not a single free block of 2GB is available, you'll get out of memory exceptions too. And keep in mind that the normal Heap memory is only part of the memory the VM process is using. So on a 32bit machine you will probably never be able to set Xmx to 2048MB.



                            I would also suggest to set min an max memory to the same value, because in this case as soon as the VM runs out of memory the frist time 1GB is allocated from the start, the VM then allocates a new block (assuming it increases with 500MB blocks) of 1,5GB after that is allocated, it would copy all the stuff from block one to the new one and free Memory after that. If it runs out of Memory again the 2GB are allocated and the 1,5 GB are then copied, temporarily allocating 3,5GB of memory.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Sep 28 '12 at 14:46









                            Christofer DutzChristofer Dutz

                            1,60711726




                            1,60711726























                                2














                                I got same problem when compiling Druid.io, increasing the MaxDirectMemorySize finally worked.



                                export MAVEN_OPTS="-Xms8g -Xmx8g -XX:MaxDirectMemorySize=4096m"





                                share|improve this answer
























                                • Curious, MaxDirectMemorySize is ostensibly unbounded by default (i.e. you added a limit, not adjusted a preexisting one).

                                  – Tomer Gabel
                                  Jun 18 '17 at 11:04
















                                2














                                I got same problem when compiling Druid.io, increasing the MaxDirectMemorySize finally worked.



                                export MAVEN_OPTS="-Xms8g -Xmx8g -XX:MaxDirectMemorySize=4096m"





                                share|improve this answer
























                                • Curious, MaxDirectMemorySize is ostensibly unbounded by default (i.e. you added a limit, not adjusted a preexisting one).

                                  – Tomer Gabel
                                  Jun 18 '17 at 11:04














                                2












                                2








                                2







                                I got same problem when compiling Druid.io, increasing the MaxDirectMemorySize finally worked.



                                export MAVEN_OPTS="-Xms8g -Xmx8g -XX:MaxDirectMemorySize=4096m"





                                share|improve this answer













                                I got same problem when compiling Druid.io, increasing the MaxDirectMemorySize finally worked.



                                export MAVEN_OPTS="-Xms8g -Xmx8g -XX:MaxDirectMemorySize=4096m"






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 2 '17 at 12:32









                                hahakubilehahakubile

                                3,38721917




                                3,38721917













                                • Curious, MaxDirectMemorySize is ostensibly unbounded by default (i.e. you added a limit, not adjusted a preexisting one).

                                  – Tomer Gabel
                                  Jun 18 '17 at 11:04



















                                • Curious, MaxDirectMemorySize is ostensibly unbounded by default (i.e. you added a limit, not adjusted a preexisting one).

                                  – Tomer Gabel
                                  Jun 18 '17 at 11:04

















                                Curious, MaxDirectMemorySize is ostensibly unbounded by default (i.e. you added a limit, not adjusted a preexisting one).

                                – Tomer Gabel
                                Jun 18 '17 at 11:04





                                Curious, MaxDirectMemorySize is ostensibly unbounded by default (i.e. you added a limit, not adjusted a preexisting one).

                                – Tomer Gabel
                                Jun 18 '17 at 11:04











                                1














                                _JAVA_OPTIONS="-Xmx3G" mvn clean install





                                share|improve this answer






























                                  1














                                  _JAVA_OPTIONS="-Xmx3G" mvn clean install





                                  share|improve this answer




























                                    1












                                    1








                                    1







                                    _JAVA_OPTIONS="-Xmx3G" mvn clean install





                                    share|improve this answer















                                    _JAVA_OPTIONS="-Xmx3G" mvn clean install






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Nov 17 '18 at 13:57









                                    Suraj Rao

                                    23k85770




                                    23k85770










                                    answered Nov 17 '18 at 13:53









                                    DeviceManagerDeviceManager

                                    112




                                    112























                                        0














                                        Using .mvn/jvm.config worked for me plus has the added benefit of being linked with the project.






                                        share|improve this answer




























                                          0














                                          Using .mvn/jvm.config worked for me plus has the added benefit of being linked with the project.






                                          share|improve this answer


























                                            0












                                            0








                                            0







                                            Using .mvn/jvm.config worked for me plus has the added benefit of being linked with the project.






                                            share|improve this answer













                                            Using .mvn/jvm.config worked for me plus has the added benefit of being linked with the project.







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Mar 23 '16 at 18:39









                                            colinbescolinbes

                                            4617




                                            4617























                                                0














                                                This below configuration working in my case



                                                <plugin>
                                                <groupId>org.apache.maven.plugins</groupId>
                                                <artifactId>maven-surefire-plugin</artifactId>
                                                <version>${maven-surefire-plugin.version}</version>
                                                <configuration>
                                                <verbose>true</verbose>
                                                <fork>true</fork>
                                                <argLine>-XX:MaxPermSize=500M</argLine>
                                                </configuration>
                                                </plugin>


                                                Try to use -XX:MaxPermSize instead of -XX:MaxPermGen






                                                share|improve this answer






























                                                  0














                                                  This below configuration working in my case



                                                  <plugin>
                                                  <groupId>org.apache.maven.plugins</groupId>
                                                  <artifactId>maven-surefire-plugin</artifactId>
                                                  <version>${maven-surefire-plugin.version}</version>
                                                  <configuration>
                                                  <verbose>true</verbose>
                                                  <fork>true</fork>
                                                  <argLine>-XX:MaxPermSize=500M</argLine>
                                                  </configuration>
                                                  </plugin>


                                                  Try to use -XX:MaxPermSize instead of -XX:MaxPermGen






                                                  share|improve this answer




























                                                    0












                                                    0








                                                    0







                                                    This below configuration working in my case



                                                    <plugin>
                                                    <groupId>org.apache.maven.plugins</groupId>
                                                    <artifactId>maven-surefire-plugin</artifactId>
                                                    <version>${maven-surefire-plugin.version}</version>
                                                    <configuration>
                                                    <verbose>true</verbose>
                                                    <fork>true</fork>
                                                    <argLine>-XX:MaxPermSize=500M</argLine>
                                                    </configuration>
                                                    </plugin>


                                                    Try to use -XX:MaxPermSize instead of -XX:MaxPermGen






                                                    share|improve this answer















                                                    This below configuration working in my case



                                                    <plugin>
                                                    <groupId>org.apache.maven.plugins</groupId>
                                                    <artifactId>maven-surefire-plugin</artifactId>
                                                    <version>${maven-surefire-plugin.version}</version>
                                                    <configuration>
                                                    <verbose>true</verbose>
                                                    <fork>true</fork>
                                                    <argLine>-XX:MaxPermSize=500M</argLine>
                                                    </configuration>
                                                    </plugin>


                                                    Try to use -XX:MaxPermSize instead of -XX:MaxPermGen







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Feb 11 '18 at 20:54

























                                                    answered Feb 11 '18 at 20:40









                                                    Narayan YerrabachuNarayan Yerrabachu

                                                    835921




                                                    835921























                                                        0














                                                        While building the project on Unix/Linux platform, set Maven options syntax as below. Notice that single qoutation signs, not double qoutation.



                                                        export MAVEN_OPTS='-Xmx512m -XX:MaxPermSize=128m'





                                                        share|improve this answer




























                                                          0














                                                          While building the project on Unix/Linux platform, set Maven options syntax as below. Notice that single qoutation signs, not double qoutation.



                                                          export MAVEN_OPTS='-Xmx512m -XX:MaxPermSize=128m'





                                                          share|improve this answer


























                                                            0












                                                            0








                                                            0







                                                            While building the project on Unix/Linux platform, set Maven options syntax as below. Notice that single qoutation signs, not double qoutation.



                                                            export MAVEN_OPTS='-Xmx512m -XX:MaxPermSize=128m'





                                                            share|improve this answer













                                                            While building the project on Unix/Linux platform, set Maven options syntax as below. Notice that single qoutation signs, not double qoutation.



                                                            export MAVEN_OPTS='-Xmx512m -XX:MaxPermSize=128m'






                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Jul 19 '18 at 6:18









                                                            ÖMER TAŞCIÖMER TAŞCI

                                                            1926




                                                            1926























                                                                0














                                                                This happens in big projects on Windows when cygwin or other linux emulator is used(git bash). By some coincidence, both does not work on my project, what is an big open source project. In a sh script, a couple of mvn commands are called. The memory size grows to heap size bigger that specified in Xmx and most of the time in a case second windows process is started. This is making the memory consumption even higher.



                                                                The solution in this case is to use batch file and reduced Xmx size and then the maven operations are successful. If there is interest I can reveal more details.






                                                                share|improve this answer




























                                                                  0














                                                                  This happens in big projects on Windows when cygwin or other linux emulator is used(git bash). By some coincidence, both does not work on my project, what is an big open source project. In a sh script, a couple of mvn commands are called. The memory size grows to heap size bigger that specified in Xmx and most of the time in a case second windows process is started. This is making the memory consumption even higher.



                                                                  The solution in this case is to use batch file and reduced Xmx size and then the maven operations are successful. If there is interest I can reveal more details.






                                                                  share|improve this answer


























                                                                    0












                                                                    0








                                                                    0







                                                                    This happens in big projects on Windows when cygwin or other linux emulator is used(git bash). By some coincidence, both does not work on my project, what is an big open source project. In a sh script, a couple of mvn commands are called. The memory size grows to heap size bigger that specified in Xmx and most of the time in a case second windows process is started. This is making the memory consumption even higher.



                                                                    The solution in this case is to use batch file and reduced Xmx size and then the maven operations are successful. If there is interest I can reveal more details.






                                                                    share|improve this answer













                                                                    This happens in big projects on Windows when cygwin or other linux emulator is used(git bash). By some coincidence, both does not work on my project, what is an big open source project. In a sh script, a couple of mvn commands are called. The memory size grows to heap size bigger that specified in Xmx and most of the time in a case second windows process is started. This is making the memory consumption even higher.



                                                                    The solution in this case is to use batch file and reduced Xmx size and then the maven operations are successful. If there is interest I can reveal more details.







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Jan 7 at 20:48









                                                                    zhristzhrist

                                                                    350113




                                                                    350113






























                                                                        draft saved

                                                                        draft discarded




















































                                                                        Thanks for contributing an answer to Stack Overflow!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid



                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.


                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function () {
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12498738%2fmaven-out-of-memory-build-failure%23new-answer', 'question_page');
                                                                        }
                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        這個網誌中的熱門文章

                                                                        Xamarin.form Move up view when keyboard appear

                                                                        Post-Redirect-Get with Spring WebFlux and Thymeleaf

                                                                        Anylogic : not able to use stopDelay()