3

Am running my application from a payara micro UberJar and would like to increase the memory allocated to the application. How can I do this at the point of creating the uberJar?

abulkay
  • 409
  • 4
  • 13

2 Answers2

5

There are a couple of ways you can do this. The first way I'll mention is the preferred way:

1. Use asadmin commands

The latest edition of Payara Micro introduces an option called --postbootcommandfile which allows you to run asadmin commands against Payara Micro. Your file should include something like this:

delete-jvm-options -Xmx=512m
create-jvm-options -Xmx=1g
create-jvm-options -Xms=1g

You will need to make sure you delete the existing options before applying new ones.

You can then use the file similar to this:

java -jar payara-micro.jar --postbootcommandfile myCommands.txt --deploy myApp.war --outputuberjar myPayaraMicroApp.jar

Your settings should now persist in the resulting Uber JAR.

2. Supply a custom domain.xml

The alternative to this would be modifying a domain.xml of your own and overriding the in-built domain.xml with your own.

You can use the --rootdir option to get Payara Micro to output its configuration to a directory so you can make changes there. This process is outlined in this blog:
http://blog.payara.fish/working-with-external-configuration-files-in-payara-micro

If you already have a custom domain.xml to hand, you can use the --domainconfig property to supply it, as follows:

java -jar payara-micro.jar --domainconfig myCustomDomain.xml --deploy myApp.war --outputuberjar myPayaraMicroApp.jar

After following either of these methods, you can simply start the resulting JAR and all the settings and configuration will be applied:

java -jar myPayaraMicroApp.jar
Mike
  • 4,852
  • 1
  • 29
  • 48
  • Is this really relevant for Payara Micro? I think that the options don't apply since Payara Micro is not executing in a separate JVM. The command line options should be applied when running the JAR: `java -Xmx=1g -Xms=1g -jar myPayaraMicroApp.jar`, otherwise I think they will be ignored. – OndroMih May 01 '17 at 09:58
  • AFAIK it would be, but system properties would override any other settings. Would be worth checking, though. System properties are probably a better way of doing it since 171,though, since all command line options are now read as system properties. It allows for a nice single micro.properties config file where all this can be set too. – Mike May 01 '17 at 10:02
  • My point is that as java -jar payara-micro.jar starts a single JVM process, it's not possible to set the JVM arguments from within the process, not even with system properties. The JVM arguments must be set before a JVM is started. – OndroMih May 01 '17 at 10:42
  • This would be like setting the JVM heap size for your payara server, after which a restart of the server is needed to restart the JVM. @OndrejM – abulkay Sep 04 '17 at 12:50
  • Yes, @abulkay. If you change JVM properties in server's configuration, a restart is needed, and the new process is started with the JVM options specified in the config. For Payara Micro there's no way to restart the app except kill and start again. At this point, you have to supply command line parameters to the java command manually when starting again. There's no way for reading JVM options from a file and restarting Payara Micro from within Payara Micro. – OndroMih Sep 04 '17 at 20:17
1

Payara Micro uber JAR is a plain JAR and it doesn't start a new JVM like Payara Server does. Therefore there's no way to modify JVM memory settings from within the JAR as the JVM is already started. Although it's possible to add the JVM settings into the Payara Micro configuration, they are ignored and not applied. Those configuration values are only used within Payara Server.

With Payara Micro uber JAR, you need to specify the JVM options on the command line, like this:

java -Xmx=1g -Xms=1g -jar myPayaraMicroApp.jar

If you need to specify JVM arguments in the uber JAR, you need to use a solution like capsule.io to wrap the JAR into a launcher JAR that would spawn a separate JVM for Payara Micro and pass the arguments to it.

OndroMih
  • 7,280
  • 1
  • 26
  • 44
  • The [Eclipse IDE launcher](https://wiki.eclipse.org/Equinox_Launcher) does the same thing. It's a native process, which reads JVM arguments from a file and starts a new JVM process. – OndroMih Sep 04 '17 at 20:20
  • Thanks OndroMih - we also faced this Issue with Payara Micro. jvm-options in domain.xml like Xmx or Xms are ignored. Things like configuring the keystorepath are possible via domain.xml within the jvm-options declaration. Maybe the following can be said: all jvm options beginning with "-X" having no effect when defined in domain.xml, but all jvm options beginning with "-D" do have an effect. Is that correct? – snukone Jul 30 '19 at 14:57
  • With Payara Micro, none of the JVM options in domain.xml have any effect. All has to be defined on the command line like for any other Java JAR file. Payara Micro runs as any other Java program, it doesn't launch another JVM process, so it can't configure the JVM itself. – OndroMih Aug 12 '19 at 13:59
  • But keystorepath is accepted via -D Parameter in jvm options of Domain XML- we tested it successfully! Same goes with path to truststore. – snukone Aug 12 '19 at 14:02
  • Well, I wasn't aware of it. This is an undocumented feature. The officially supported way is to define all system properties on command line or via a separate properties file referenced on command line: https://docs.payara.fish/documentation/payara-micro/configuring/config-sys-props.html – OndroMih Aug 13 '19 at 16:38
  • Ah ok, nice to know :) thank u very much for your Expertise! It helped me a lot to understand this. – snukone Aug 13 '19 at 21:33