解决Maven/Ant中OutOfMemory错误

本文介绍了解决Maven在处理大型项目时遇到的内存溢出问题的方法。通过设置MAVEN_OPTS和ANT_OPTS来增加分配给Maven的内存,确保构建过程顺利进行。文中提供了在不同操作系统中进行配置的具体步骤。

当Maven项目很大,或者你运行诸如 mvn site 这样的命令的时候,maven运行需要很大的内存,在默认配置下,就可能遇到java的堆溢出

exception:OutOfMemoryError

 

set 

MAVEN_OPTS=-Xms256m -Xmx512m -XX:PermSize=256m -XX:MaxPermSize=384m

ANT_OPTS=-Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m

 

Windows #

  1. Go into your Control Panel > System > Advanced System Settings > Environment Variables settings
  2. Click "New" in your User Variables
  3. Variable name: "ANT_OPTS"
  4. Variable value: "-Xmx1024m -XX:MaxPermSize=512m"
Setting ANT_OPTS in ant.bat #
  1. Edit the ant.bat file in your ant home folder.
  2. Add the following line at the top of the file:
set ANT_OPTS=-Xmx1024m -XX:MaxPermSize=512m


Ubuntu #

Edit ~/.bashrc or ~/.bash_profile to include:

ANT_OPTS="-Xmx1024m -XX:MaxPermSize=512m"
export ANT_OPTS

Make sure to exit the command prompt to realize the changes.

Mac OS X #

~/.profile

Append:

export ANT_OPTS="-Xmx1024m -XX:MaxPermSize=512m"
构建进程终止异常: "D:\work\w\idea\2023.2\exe\IntelliJ IDEA 2023.2\jbr\bin\java.exe" -Xmx700m -Djava.awt.headless=true "-Djna.boot.library.path=D:\work\w\idea\2023.2\exe\IntelliJ IDEA 2023.2/lib/jna/amd64" -Djna.nosys=true -Djna.noclasspath=true --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dexternal.project.config=C:\Users\Administrator\AppData\Local\JetBrains\IntelliJIdea2023.2\projects\zy-microservice.b93186e1\external_build_system -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Didea.IntToIntBtree.page.size=32768 -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=-2546703222879205225 -Dfile.encoding=GBK -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2023.2 -Djps.language.bundle=C:/Users/Administrator/AppData/Roaming/JetBrains/IntelliJIdea2023.2/plugins/zh.232.322/lib/zh.232.322.jar "-Didea.home.path=D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2" -Didea.config.path=C:/Users/Administrator/AppData/Roaming/JetBrains/IntelliJIdea2023.2 -Didea.plugins.path=C:/Users/Administrator/AppData/Roaming/JetBrains/IntelliJIdea2023.2/plugins -Djps.log.dir=C:/Users/Administrator/AppData/Local/JetBrains/IntelliJIdea2023.2/log/build-log "-Djps.fallback.jdk.home=D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/jbr" -Djps.fallback.jdk.version=17.0.7 -Dio.netty.noUnsafe=true -Djava.io.tmpdir=C:/Users/Administrator/AppData/Local/JetBrains/IntelliJIdea2023.2/compile-server/zy-microservice_e8c74617/_temp_ -Djps.backward.ref.index.builder=true -Dtmh.instrument.annotations=true -Dtmh.generate.line.numbers=true "-Djps.kotlin.home=D:\work\w\idea\2023.2\exe\IntelliJ IDEA 2023.2\plugins\Kotlin\kotlinc" -Dkotlin.incremental.compilation=true -Dkotlin.incremental.compilation.js=true -Dkotlin.daemon.enabled -Dkotlin.daemon.client.alive.path=\"C:\Users\Administrator\AppData\Local\Temp\kotlin-idea-2076706333136374432-is-running\" -Dide.propagate.context=false -classpath "D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/jps-launcher.jar" org.jetbrains.jps.cmdline.Launcher "D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/jps-builders.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/jps-builders-6.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/jps-javac-extension.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/util-8.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/util_rt.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/platform-loader.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/annotations.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/protobuf.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/jps-model.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/javac2.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/forms_rt.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/aether-dependency-resolver.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/maven-resolver-connector-basic.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/maven-resolver-transport-file.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/maven-resolver-transport-http.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/idea_rt.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/JavaEE/lib/jasper-v2-rt.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/Kotlin/lib/jps/kotlin-jps-plugin.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/lib/util-8.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/eclipse/lib/eclipse-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/eclipse/lib/eclipse-common.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/ant/lib/ant-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/JavaEE/lib/javaee-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/uiDesigner/lib/jps/java-guiForms-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/space/lib/space-java-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/devkit/lib/devkit-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/devkit/lib/devkit-runtimeModuleRepository-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/platform-langInjection/lib/java-langInjection-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/javaFX/lib/javaFX-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/javaFX/lib/javaFX-common.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/Groovy/lib/groovy-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/Groovy/lib/groovy-constants-rt.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/maven/lib/maven-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/gradle-java/lib/gradle-jps.jar;D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/JPA/lib/jps/javaee-jpa-jps.jar" org.jetbrains.jps.cmdline.BuildMain 127.0.0.1 50184 8aee60a4-3246-426d-9ae0-491a88914652 C:/Users/Administrator/AppData/Local/JetBrains/IntelliJIdea2023.2/compile-server Be careful, logger will be shut down earlier than application: Unable to make field private static java.util.IdentityHashMap java.lang.ApplicationShutdownHooks.hooks accessible: module java.base does not "opens java.lang" to unnamed module @2c8d66b2 Build process started. Classpath: D:/work/w/idea/2023.2/exe/IntelliJ IDEA 2023.2/plugins/java/lib/jps-launcher.jar # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (malloc) failed to allocate 1943216 bytes for Chunk::new # An error report file with more information is saved as: # C:\Users\Administrator\AppData\Local\JetBrains\IntelliJIdea2023.2\compile-server\hs_err_pid19940.log # # Compiler replay data is saved as: # C:\Users\Administrator\AppData\Local\JetBrains\IntelliJIdea2023.2\compile-server\replay_pid19940.log
最新发布
09-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值