Using Apache Tika 1.9 in Netbeans 8.0.2 and Java 8 produces HUGE executable. What to do to reduce size?

我们两清 提交于 2019-12-11 05:17:11

问题


I haven't had much luck with external libraries, so I've just included the source for utilities in any project that uses utilities.

Now I have a project that requires Apache Tika, so I have to have a library setup something like this:

But to run the program from outside Netbeans, I apparently (per readme.txt in dist folder) need to zip the .jar and lib folder, unzip that zipped file, extract the contents, and run from wherever it's extracted to.

But the Tika lib is 45MB.

I only use 5 objects from the tika-app-1.9.jar library file:

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MimeTypeException;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.sax.BodyContentHandler;

How do I make a tiny subset of Tika objects into a library that will be a lot smaller than 45MB?

Or am I missing the point of what I SHOULD do?


回答1:


You should only include the tika-core and tika-parsers components, these two files should be no more than 1.2MB.

The tika-app jar is described on the home page as this:

Tika application. Combines the above components and all the external parser libraries into a single runnable jar with a GUI and a command line interface.

So it has a lot of extra things, which your app does not need.




回答2:


For long run it's better to migrate to maven or something similar. Then exclude unnecessary dependencies. E.g. if you don't need scientific formats which are parsed using NetCDF library you can exclude it:

<dependency>
  <groupId>org.apache.tika</groupId>
  <artifactId>tika-parsers</artifactId>
  <version>1.10</version>
  <exclusions>
    <exclusion>
      <groupId>edu.ucar</groupId>
      <artifactId>netcdf</artifactId>
    </exclusion>
  </exclusions>
</dependency>

But be careful, it can lead to NoClassDefFoundError if you exclude something required by parsers you use.



来源:https://stackoverflow.com/questions/31919171/using-apache-tika-1-9-in-netbeans-8-0-2-and-java-8-produces-huge-executable-wha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!