Search code examples
jvmpayara-micro

Increase memory allocated to application deployed to payara micro


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?


Solution

  • 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