Runnable jar runs too slow compared to eclipse project

雨燕双飞 提交于 2019-12-12 08:55:25

问题


I have extracted a jar file from an eclipse project but it runs too slow. It takes almost twenty minutes to complete and the eclipse project only takes some seconds. I exported runnable jar with library handling with all three differenct choices. I also exported jar file with all library handling choices. I also run jar file with command:

java -Xmx2048m -Xms1024m -jar "finalJar.jar"

I have removed all System.out.println except the last one that gives me the answer. What can I do to export a jar that is almost fast as the original project? Or run it with a different way to be faster? Because the difference in time is too big and I don't understand why.


回答1:


Using the option "Extract required libraries into generated file" helped me a lot, it's faster now.

The option "Package required libraries into generated JAR" copy the libs you use as jar files into your own jar file and the JVM needs to open it (or even extract if it's compacted) when you run the application.




回答2:


I found the problem I hope it will help someone else. First it is faster if you export a runnable jar file with option: "Extract required libraries into generated file" And second the biggest problem was that I was using input arguments like:

String inputArgument = args[0];

and then I was using the inputArguments somewhere after in code. So I erased this and I was using args[0] wherever I needed this input argument in the code. I am not sure if it is the best thing to do but it worked for me and it had a lot of difference in time.



来源:https://stackoverflow.com/questions/22685103/runnable-jar-runs-too-slow-compared-to-eclipse-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!