1

I have a jar file which is run only through script in Windows due to 4G RAM allocation,like this:

java -Xmx4g MyApp.jar

and it hangs when clicking on the jar file, the question is whether it is possible to put an error message in the java program that says if the user clicks the jar file It should run the script

A solution that allocates RAM programmatically, like this:

, is not very convenient

This did not help either

Edit: I came up with this idea:

long heapSize = Runtime.getRuntime().totalMemory();
                Double heapSizeG= Double.valueOf(heapSize/1000000000);//This condition is inappropriate because the heapSize is not expected 
                if(heapSizeG >3 ) //it is false after java -Xmx4g MyApp.jar, why? 
                {
                 //Do Something(); //not working                       
                }
Ddll
  • 85
  • 8
  • 1
    Are you able to change the executable file that the user is clicking on? Does it have to be the jar file? If you're able to adjust it, then take a look at http://winrun4j.sourceforge.net/ or create your own batch file https://codersathi.com/run-java-jar-using-batch-file/#:~:text=If%20you%20want%20to%20keep,automatically%20start%20a%20jar%20file.. Let me know if it's useful and I will add it as an answer. – wleao Jul 02 '22 at 12:31
  • @wleao I have all java source files ,Can the solution be just Jar File? – Ddll Jul 03 '22 at 04:33
  • the main problem is that you have to provide JVM arguments to the JVM and that is done before loading your far file. – wleao Jul 03 '22 at 18:09
  • @wleao i have an idea and edit post – Ddll Jul 04 '22 at 03:39

0 Answers0