简体   繁体   中英

Runnable jar runs too slow compared to eclipse project

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.

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.

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.

I faced the same issue. The eclipse took 5 seconds to run the application while the jar took 3 minutes. This is due to the way I exported the runnable jar file.

These are mainly two ways to export as a Runnable jar in eclipse .

1). Package required libraries into jar

  • This will add actual jar files of the libraries into your jar . This is the cleanest since it separates application class files with library JARs.
  • The downside is this makes runnable jar perform very slow.

2). 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 taking 5 seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM