How Jar Files Work When Using runtime.getRuntime (). Exec ()

I am trying to create a jar file that will execute my game with one click. My game exceeds the standard java heap memory, so I need to run my code with -Xmx1000m. I am studying online, and unfortunately it seems that there is no way to tell the jar file to make it amuse my code with more than default memory. Instead, I created another class that will use the runtime to compile my code from another main method and created a jar file using this:

import java.io.*; public class RuntimeExec{ public static void main(String[] args){ try { Process process = Runtime.getRuntime().exec("java -Xmx1000m Controller"); process.waitFor(); int exitCode = process.exitValue(); if(exitCode == 0) { /* success*/ } else { /*failed*/ } } catch (Exception e) {e.printStackTrace();} } } 

This works, but I think it only works because it runs my existing class in a folder, and not the one I stored in the bank. Is there a way for the jar to run the class inside or combine two different jars that will allow me to get around the memory heap problem?

+4
source share
2 answers

There are many ways to do this:

  • As you mentioned, having another Jar file that runs your game file
  • As mentioned in @Perception, you have a batch file that will launch your game. But be careful if you download from the Net site, the user will need to set permissions for the script to run
  • Create an installer. On a Mac, using the Oracle Java App bundler for Java 7, the Apple App bundler for Java 6 creates a .app file. You still cannot redistribute it, as the necessary permissions will not be set. Create dmg for the application file. This can be used for distribution. A similar installer for Windows

A third method would be best, since you can successfully package dependencies, set all JVM arguments, etc.

0
source

The complete solution for easy installation for users is to deploy the application. using Java Web Start . He can install RAM for the application, as well as set a shortcut on the desktop to run it. JWS is much more reliable than a (poorly implemented) call to exec .


However, if JWS for some reason is not suitable for this application, see IWantToBeBig for hacking, which will make Jar have enough memory (similar to how you use exec above, but a little more reliable when using ProcessBuilder to restart an application that does not have enough memory )

Organizing a desktop shortcut that allows the user to launch it with one click remains as an exercise for the reader.

0
source

All Articles