1

I created a class that gives a text file containing system performance as output. I want to run it as an executable Jar. but when I run the Jar I want to increase the heap to 1 GB.

If we run this program I can do this by running like this:

java -Xms1200m  -Xmx1300m Sample

But how can I increase heap space using an executable Jar? When I click on the jar it must execute with a heap space of 1 GB.

dimo414
  • 47,227
  • 18
  • 148
  • 244
Amith
  • 1,907
  • 5
  • 29
  • 48
  • 1
    Possible duplicate of [Can I set Java max heap size for running from a jar file?](http://stackoverflow.com/questions/1018217/can-i-set-java-max-heap-size-for-running-from-a-jar-file) – dimo414 Jun 30 '16 at 13:30

3 Answers3

8
 java -Xms1200m -Xmx1300m -jar FILENAME.jar

Define this somewhere in the jar File or in the Manifest is not possible:

Can I set Java max heap size for running from a jar file?

Community
  • 1
  • 1
Thargor
  • 1,862
  • 14
  • 24
  • i want to set up heap space for an executable jar – Amith Aug 09 '12 at 08:59
  • Then check out the link in this answer. It is not possible with just a jar, you need some wrapper (shell script, web start, whatever) – Thilo Aug 09 '12 at 09:05
0

As already mentioned: it unfortunately is not possible (without creating a wrapper, whether shortcut/script/executable ...).

If you're only running on Windows, I can recommend Launch4J to create an executable wrapper that can apply these settings on execution:

Wrapping it in a executable has other benefits:

  • If a suitable version of Java is not found, it will prompt the user to download it
  • Windows 7 Start Menu will treat it properly (highlighting it as a new application after installation)
  • Windows Firewall will treat it properly
Luke Usherwood
  • 3,082
  • 1
  • 28
  • 35
0
<launch4jConfig>
  <dontWrapJar>false</dontWrapJar>
  <headerType>gui</headerType>
  <jar>PATH_OF_YOUR_JAR</jar>
  <outfile>PATH_OF_YOUR_EXE</outfile>
  <errTitle></errTitle>
  <cmdLine>-log_file=logs\\hp</cmdLine>
  <chdir></chdir>
  <priority>normal</priority>
  <downloadUrl>http://java.com/download</downloadUrl>
  <supportUrl></supportUrl>
  <customProcName>true</customProcName>
  <stayAlive>false</stayAlive>
  <manifest></manifest>
  <icon>PATH_OF_THE_ICON</icon>
  <singleInstance>
    <mutexName>APPLICATION_NAME</mutexName>
    <windowTitle></windowTitle>
  </singleInstance>
  <jre>
    <path>jre-w32\</path>
    <minVersion></minVersion>
    <maxVersion></maxVersion>
    <jdkPreference>preferJre</jdkPreference>
    <initialHeapSize>512</initialHeapSize>  
    <maxHeapSize>1024</maxHeapSize>
  </jre>
</launch4jConfig>

It is a launch4j Config file, here you can specify the heap size as per your requirement.