Occasionally the user may benefit from increasing the maximum memory allocation pool for a Java virtual machine (JVM) upon execution. This can be accomplished using the “-Xmx” command with the proceeding memory allocation. For example if we wanted to specify 16 Gigabytes we would put -Xmx16G. This is particularly useful when running large-scale simulations on a high performance cluster (see jar file creation).

When executing a java jar file in command line use “java -Xmx16G -jar TargetJarFile.jar” to execute your model with extra memory. However, while in the IdeaJ environment this is accomplished by the following steps:

  1. Click on “Edit Configurations” from the dropdown menu on the top right of Intellij next to the run button.
  2. Specify the memory using the -Xmx argument in the “VM Arguments” box.

9.1 Jar File Creation and Execution

When resources are needed that only a high-performance computing (HPC) environment can provide it may be useful to build a jar file of your model to execute independent of any IDE. IntelliJ IDEA makes it very easy to build this ‘artifact.’ There are two ways of executing your jar file. One is with command line arguments and the other is without. The process of building a jar file is the same for both, but with command line arguments you will set variables using ‘args[].’ With either case, the GUI should not be used within an HPC command line environment unless you are using port forwarding for graphics. This is dependent on your HPC environment and thus will not be covered here. To simply build a jar file from your project follow these steps:

  1. Navigate to “File’ -> ‘Project Structure
  2. On the left, where we set up our libraries, click on “Artifacts
  3. Click the “+” button and select “JAR,” finally click “From modules with dependencies...”, You will only need to do this once!
  4. Leave all the default options in place.
  5. Click “Apply” and then “Ok
  6. From here go the top menu bar, click on “Build -> Build Artifacts...
  7. Using this you can select “Build,” “Rebuild,” “Clean”, or edit which will take you back to Step 3.
  8. Just choose “Build” (for the first time, you can use “Rebuild” later).
  9. Your jar file is located within the project directory in the “out/artifacts/jarname/file.jar,”
  10. the Jar file can be moved to another machine that has Java 8 or above for execution.
  11. to run the jar file, enter something like: “Java -jar -Xmx16G /path/to/jar/file.jar arg1 arg2 arg3” where the optional flag “-Xmx16G” specifies that we want to use 16GB of memory for the program, “/path/to/jar/file.jar” is the path to the jar file, and “arg1 arg2 arg3” are optional arguments that will show up in your program in the “String[] args” array in the main function.