在命令提示符下执行.jar文件时出现Java堆空间问题

时间:2018-08-16 07:12:06

标签: java heap-memory

我已经创建了具有依赖项的maven java项目,并在其中创建了jar文件,以通过命令提示符执行。

请从pom.xml文件中找到我的构建详细信息

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.es.utility.DocumentBulkIndex</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

在命令提示符下执行此jar文件时

java -jar ElasticSearchDocumentIndex-1.0.0-SNAPSHOT-jar-with-dependencies.jar正在获得java heap space issue.

我不太确定我可以在哪里增加堆空间。

if(file.exists() && !file.isDirectory()) {

PrintWriter out1=null;

try {
    FileInputStream fileInputStreamReader = new FileInputStream(file);
    byte[] bytes = new byte[(int) file.length()];   /// Java Heap Space issue is happening here.
    fileInputStreamReader.read(bytes);
    encodedfile = new String(Base64.getEncoder().encodeToString(bytes));
    fileInputStreamReader.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at com.es.utility.DocumentBulkIndex.main(DocumentBulkIndex.java:195)

0 个答案:

没有答案