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.
You may check Java VM parameters (like used GC, maximum memory etc). For data-intensive applications GC could slow things down a lot.
Yes I have the same problem. I have Experimented and got a solution!
just choose "Package required libraries into jar" while making the jar files. this solution worked fine with me and hope this will also for for you to.
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
jar
files of the libraries into your jar
. This is the cleanest since it separates application class files with library JARs.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.
Having said that, best approach would be to use maven
build tool. By using Maven
it is very easy to maintain and handle third party libraries. You may have a look.
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.