| The code is as follows: |
Copy code |
[INFO] Building jar:/home/dl9pf/svn/mindquarry-jcr-changes/target/mindquarry-migration-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Java heap space
[INFO] ------------------------------------------------------------------------
[INFO] Trace
Java. lang. OutOfMemoryError: Java heap space
At java. lang. AbstractStringBuilder. expandCapacity (AbstractStringBuilder. java: 99)
At java. lang. AbstractStringBuilder. append (AbstractStringBuilder. java: 518)
...
At org. codehaus. classworlds. Launcher. launchEnhanced (Launcher. java: 315)
At org. codehaus. classworlds. Launcher. launch (Launcher. java: 255)
At org. codehaus. classworlds. Launcher. mainWithExitCode (Launcher. java: 430)
At org. codehaus. classworlds. Launcher. main (Launcher. java: 375)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 minutes 14 seconds
[INFO] Finished at: Wed Sep 05 07:44:55 cest2007
[INFO] Final Memory: 37 M/63 M
[INFO] ------------------------------------------------------------------------
|
The solution is to adjust the value of the java heap size.
In Windows
Find the file % M2_HOME % binmvn. bat, which is the script file for starting Maven. In this file, you can see a line of comment:
| The code is as follows: |
Copy code |
|
@ REM set MAVEN_OPTS =-Xdebug-Xnoagent-Djava. compiler = NONE... |
It means you can set some Maven parameters, and we will add a line below the comment:
| The code is as follows: |
Copy code |
Set MAVEN_OPTS =-Xms128m-Xmx512m
|
Then, when you run the Maven command such as mvn-version, you will see the following output:
| The code is as follows: |
Copy code |
|
E: test> mvn-version
E: test> set MAVEN_OPTS =-Xms128m-Xmx512m
Maven version: 2.0.9
Java version: 1.6.0 _ 07
OS name: "windows 2003" version: "5.2" arch: "x86" Family: "windows" |
We can see that the configured Maven option takes effect, and the OutOfMemoryError can also be resolved accordingly.
In Linux
You can also solve this problem by setting environment variables, for example, editing the file/etc/profile as follows:
| The code is as follows: |
Copy code |
MAVEN_OPTS =-Xmx512m
Export JAVA_HOME MAVEN_HOME MAVEN_OPTS JAVA_BIN PATH CLASSPATH
|
If you use Hudson
Using Hudson + Maven for continuous integration, and unfortunately encountered similar errors, the above two methods will no longer work, because Hudson uses its own maven-agent to start Maven, the Maven script will not be called, and the corresponding configuration will naturally become invalid.
Fortunately, Hudson also provides us with a configuration point. On the Hudson project configuration page, there is a Build area. Here we have set the Root Pom and Goals. Note that there is a "Advanced..." button in the lower-right corner of the area. Click the MAVEN_OPTS input box, and enter "-Xmx512m" here.
M2eclipse
Methods similar to the above will fail. Fortunately, m2eclipse provides configuration points. The procedure is as follows:
| The code is as follows: |
Copy code |
|
Right-click the project and choose "Run As"> "Run deployments"> "Maven Build"> "New". |
Now we will see a maven running configuration dialog box. I will not explain any other configurations here. To solve the memory overflow problem, we can select the second TAB: JRE, enter the configuration in VM arguments, for example,-Xms128m-Xmx512m.