I have a java program that reads a lot of input data from a database, manipulates it, then writes data back out to another database (using ODBC drivers, excel and access databases, on a new windows 7 machine). The program takes about 17 minutes to run from eclipse, but when I created an executable .jar file it takes an extra 10 minutes to run (27 total).
The two reasons I've found so far for slow jar files (by searching SO and google) is that they're compressed and that it takes a lot longer to write to the command prompt (or error log) than the console in eclipse. I tried creating an uncompressed jar file and it only sped up by about 10 seconds (which could have been completely random, as the run times vary by about 30 seconds anyways). I only have about 10 System.out.println()
commands in the program, so that shouldn't be slowing it down much.
Any ideas as to what is causing it to run so much slower, and if there is any way I can speed it up again? Let me know if there are any other detail that may be relevant that I should include. Thanks!
In my case, my application took 3 secs to run on eclipse while it took 2 mins when I run it from jar.
My mistake was to choose "Package required libraries into jar"
while exporting my project into runnable jar.
I tried various ways to bring down the time but nothing helped, except..
If you have other maven dependencies or jar files in your project, you should use "**Extract required libraries into generated jar**"
while exporting your project into a jar.
This solved my problem in seconds & now both my eclipse & jar file are taking same time to run the application, 2 secs.
Hope this helps the new strugglers.
Regards.
Use JAMon. It's a monitoring library, that will help you measure execution times of your code.
After you add some monitoring code to your methods, run it in Eclipse and as a JAR file, and compare the results. This should allow you to narrow the search.
Also: Check, whether you are running your JAR file, with the same java version, that the Eclipse uses (for example Java 1.4.x may be much slower than 1.6.x).
I had a similar problem. The shell was running orders of magnitude slower and it had nothing to do with console output. I tried setting JVM memory values but it didn't make any difference
The solution was to package the ANT file with all the JARs into an external folder, using the "Copy required libraries into a sub-folder next to the generated JAR" option in the "Runnable JAR File Export" wizard. Then run the main JAR with a -cp [YOURSUBFOLDER] command line option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With