Java - Runnable jar executing very huge time, How to reduce it?

1.7k Views Asked by At

I am facing a strange problem. I have a project which is taking 3 to 4 minutes to execute while running through eclipse. But, the same project, taking 3 hours to complete the same task while extracting it as a runnable jar and running.

I have tried increasing heap size by running trough command line -Xmx=3600m and -Xms=1200m parameters.

Am I going in the right way. Is there any other ways to get down the execution time of runnable jar.

2

There are 2 best solutions below

2
On

It might be worth comparing java client versions and ensuring that the machine running the jar is using the 64-bit architecture java client if available. Your eclipse runs using the JDK files (often 64-bit), but many systems only run 32-bit java clients for compatibility (specifically with browsers).

Is it possible that the jar file does not have all the libraries? Sometimes in my java programs, when an error is encountered, the process time increases significantly as the stack trace winds and unwinds. This is made worse if the error does not get handled properly.

Missing libraries could also cause this, as could running the jar in a different environment as the environment from whence you are running eclipse. Directory separators (if using files), or different ASCII characters getting brought in from APIs and such for different OS types.

Those are the causes I have noticed for unexpected java delays. Good luck!

0
On

Install Eclipse IDE and try Exporting as a Runnable Jar choosing following selection:

Option: Extract required libraries into generated jar

  • This way will extract only the actual class files from the libraries that your application uses and includes in the runnable jar file. As a result your Jar file will include your application class files as well as class files of all the libraries used by your application.

  • This method makes runnable jar perform just like it is run in your eclipse IDE.

  • Using this way I was able to run jar application without any lag and completed just as I run in eclipse IDE.