Why is my .jar file running slower than the program in eclipse?

11,314

Solution 1

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.

Solution 2

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.

Solution 3

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).

Solution 4

You may check Java VM parameters (like used GC, maximum memory etc). For data-intensive applications GC could slow things down a lot.

Share:
11,314
scaevity
Author by

scaevity

Updated on June 04, 2022

Comments

  • scaevity
    scaevity almost 2 years

    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!

  • benez
    benez about 8 years
    same here, running in eclipse was fine (nearly instant), in the jar the process was 4 minutes behind. your suggestion solved my problem
  • DragonGamer
    DragonGamer almost 7 years
    Thank you for this! Apparently that also has an enormous impact on the FXMLLoader class of JavaFX, causing it to work about 10 times slower with a "packed jar" and that although the files were outside unpacked already...
  • golimar
    golimar over 6 years
    Same result here, also I didn't need the -cp, as the manifest file already specifies the location of the sub-JARs
  • Jeremy Caney
    Jeremy Caney over 3 years
    So you're saying that this sped up your program? I ask because this is the exact opposite guidance offered by Alekhya Vemavarapu in the top-rated answer.