简体   繁体   English

为什么导出到可运行的 jar 会使应用程序占用这么多空间?

[英]Why exporting to runnable jar makes the app take so much space?

Background背景

I've made a small util that can run on Windows OS (and probably others), using SWT , WindowsBuilder, and Eclipse as IDE.我制作了一个可以在 Windows 操作系统(可能还有其他操作系统)上运行的小工具,使用 SWT、WindowsBuilder 和 Eclipse 作为 IDE。

The app is supposed to help developers to minimize their Android app's size, by converting images into WebP/Jpeg when possible.该应用程序旨在通过在可能的情况下将图像转换为 WebP/Jpeg 来帮助开发人员最小化其 Android 应用程序的大小。 It's available here .它可以在这里找到

The problem问题

I wanted to make it easier for people to run it, so I've called "export as runnable jar".我想让人们更容易运行它,所以我称之为“导出为可运行的 jar”。

Once I did this, I've noticed that from an app that takes just a few MB (needs SWT and an exe converter file), it got to be more than 20MB of storage.完成此操作后,我注意到从仅占用几 MB(需要 SWT 和 exe 转换器文件)的应用程序中,它必须超过 20MB 的存储空间。

What I tried我试过的

Looking at the files structure, I've found this:查看文件结构,我发现了这个:

在此处输入图片说明

The export wizard only has 2 steps: choosing to export as a runnable jar, and this one:导出向导只有 2 个步骤:选择导出为可运行的 jar,这一步:

在此处输入图片说明

So I can't find out how to configure it.所以我不知道如何配置它。 I tried to change the running-configuration, but it fails to run if I remove the additional jars:我试图更改运行配置,但如果我删除了额外的 jars,它就无法运行:

Error: Could not find or load main class webpifier.Main

在此处输入图片说明

Choosing to restore the default entries, I get the additional jars:选择恢复默认条目,我得到了额外的 jars:

在此处输入图片说明

The question问题

How could this be?这怎么可能? Are all those jars needed?需要所有这些罐子吗? Is it possible to avoid having such a large chunk of added files?是否有可能避免添加如此大量的文件? What is the purpose of those files?这些文件的目的是什么?

For other OSs, will replacing just the SWT file (and the converter file) be enough so that the app will run?对于其他操作系统,仅替换 SWT 文件(和转换器文件)是否足以让应用程序运行? Or should I call the "export as runnable jar" on the other OSs too (this is Java, so why should I?) ?或者我也应该在其他操作系统上调用“导出为可运行的 jar”(这是 Java,所以我为什么要这样做?)?

I'll post my comment as answer:我将发表我的评论作为答案:

How could this be?这怎么可能? Are all those jars needed?需要所有这些罐子吗?

Only you know, if all jar's are really needed.只有您知道,是否真的需要所有 jar。
All JAR's which are referenced to the project are normally also copied to the distribution-folder (also unused JAR's).所有引用到项目的 JAR 通常也被复制到分发文件夹(也是未使用的 JAR)。
Further: When you're using Eclipse-RCP or SWT, all needed Eclipse/SWT-JAR's are also copied to the distribution-folder!进一步:当您使用 Eclipse-RCP 或 SWT 时,所有需要的 Eclipse/SWT-JAR 也会复制到分发文件夹中!

I suggest using Swing instead of SWT.我建议使用Swing而不是 SWT。
Swing is already included in Java-Libs, but SWT not. Swing 已经包含在 Java-Libs 中,但 SWT 没有。
So you don't need to distribute all those SWT-JAR's.所以您不需要分发所有这些 SWT-JAR。

TIP:提示:
To reduce the distribution size of your application, try to get rid of all: org.eclipse.* -Imports要减少应用程序的分布大小,请尝试删除所有内容: org.eclipse.* -Imports

For some more important info's regarding SWT vs Swing , see here:有关SWT 与 Swing 的一些更重要的信息,请参见此处:
Java Desktop application: SWT vs. Swing Java 桌面应用程序:SWT 与 Swing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM