0

I have created maven java project with dependencies and i created jar file out of it to execute via command prompt.

Please find my build details from pom.xml file

<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>

While am executing this jar file from command prompt

java -jar ElasticSearchDocumentIndex-1.0.0-SNAPSHOT-jar-with-dependencies.jar am getting the java heap space issue..

Am not very sure where i can increase the heap space.

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)

Karthikeyan
  • 1,927
  • 6
  • 44
  • 109
  • 1
    Running such a software stack requires a lot of memory. The simply answer is to use the command line options of java to allow the JVM to use more heap space. – GhostCat Aug 16 '18 at 07:14
  • You can give some more memory ? java -Xmx1g com.mycompany.MyClass – Sahin Yanlık Aug 16 '18 at 07:28
  • Am running .jar file so am giving heap memory like this `java -Xmx6g -jar ElasticSearchDocumentIndex-1.0.0-SNAPSHOT-jar-with-dependencies.jar` is this correct..? – Karthikeyan Aug 16 '18 at 08:03

0 Answers0