Executable JAR execution different from eclipse execution



I have created an App using Java which treats excel files using Apache POI. The problem is that when I run the code from eclipse, it works fine, but when I made an executable jar for the app (Using eclipse export executable jar option), the jar is working fine but the results are different, even the size of the produced excel file is different.

I made many research, but I did not find a convenient solution.

Answer

Ah yes. I have had that same experience too a few years back.

When creating the runnable .jar in Eclipse, you can choose how .class files from libraries (such as Apache POI in this case) are handled:

  1. Package required classes (.class files) into jar file
  2. Package required libraries (.jar files) into jar file
  3. Copy libraries into a sub-folder

Interestingly, with Apache POI, the three different ways of packing create HUGE differences:

  1. In startup speed
  2. In execution speed
  3. In memory requirements (RAM)
  4. In the resulting output files

I cannot recall which gave me the expected results.
So you have to try them out yourself. (Judging by how Eclipse starts Java projects, it should be #3, libs in subfolder, that gets you the same results). But: try the others anyhow; as I said, HUGE differences ahead.

TBH Apache POI is a ‘good’ example of how software should NOT be written.
It’s awfully bloated and mega RAM hungry and has quite an interesting/odd behavior.
So I wrote my own lib for the newer .xls file format which is just a 100 times faster, smaller and more reliable. And does string caching and cell format operation optimization a lot better. So a 1000000 times better 😛

The upside is that the POI dev team knows the limitations and shortcomings of their project and offers multiple modes of processing files, to overcome said shortcomings. So, after all, kudos to them!



Source: stackoverflow