Runnable jar runs too slow compared to eclipse pro

2020-07-18 07:44发布

问题:

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.