---
title: "解决Maven/Ant中OutOfMemory错误"
author: "aniyo"
date: "2017-01-12T11:06:05Z"
tags: []
categories: ["编程语言"]
slug: "maven-ant-outofmemory"
draft: false
lastmod: "2017-01-12T11:06:05Z"
id: 2352589
url: "https://aniyo.iteye.com/blog/2352589"
---

当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 [#](https://web.liferay.com/community/wiki/-/wiki/Main/Ant+opts#section-Ant+opts-Windows)

1. Go into your Control Panel &gt; System &gt; Advanced System Settings &gt; 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 [#](https://web.liferay.com/community/wiki/-/wiki/Main/Ant+opts#section-Ant+opts-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
```

![](https://web.liferay.com/c/wiki/get_page_attachment?p_l_id=8440749&nodeId=1071674&title=Ant%20opts&fileName=SharedImages%2Fantopts_-_antdotbat.jpg)

```


```

### Ubuntu [#](https://web.liferay.com/community/wiki/-/wiki/Main/Ant+opts#section-Ant+opts-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 [#](https://web.liferay.com/community/wiki/-/wiki/Main/Ant+opts#section-Ant+opts-Mac+OS+X)

```
~/.profile
```

Append:

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