使用cygwin将java文件编译为windows本机代码
我为我的一项作业编写了一个小型 Java 应用程序。问题是老师可能没有安装JRE。我想要将java文件编译为window exe文件,以便老师可以在不安装JRE的情况下运行它。
我在 cygwin 中使用 gcj 工具,但输出应用程序似乎需要 cygwin1.dll 才能运行。我怎样才能避免这种情况,IE将应用程序需要的所有东西打包到一个文件中,这样老师就不必安装任何东西。
I have written a small java application for one of my homework. the problem is the teacher may not have JRE installed. what i want to id to compile the java file to window exe file so the teacher can run it without the JRE installed.
i use the gcj tool in the cygwin , but the output application seem to need the cygwin1.dll
to run. how can i avoid this, IE package all the things the application need to a single file, so the teacher don't have to install anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 MinGW 而不是 Cygwin。
并准备好 10 MiB 的可执行文件。
Use MinGW instead of Cygwin.
And get ready for a 10-MiB executable.
你为什么不直接要求你的老师安装一个 JRE,或者如果他们有 JRE 的话?如果您被允许使用 Java,那么我确信老师将需要拥有正确评估您作业的工具。
如果您不被允许使用Java,那么,您在想什么?
Why don't you just ask your teacher to install a JRE, or if they have one? If you are allowed to use Java, then I'm certain the teacher will be required to have the tools for properly evaluating your homework.
If you weren't allowed to use Java, well then, what were were you thinking?
在 Windows 上,将
.exe
与一组.dll
文件一起传送是很常见的。如果您使用 Microsoft Visual Studio,您的程序还需要附带 Visual Studio Redistributable Run-Time 中的一些库。 (除非您静态链接它。)Windows 上的大多数主要应用程序的安装目录都充满
dll
文件,没有它们就无法运行。2016 年中,Cygwin 项目将许可从 GPL 更改为 LGPL。这意味着您可以将程序链接到 cygwin1.dll 并重新分发它们,即使这些程序具有与常规 GPL 不兼容的许可证,例如闭源、不可自由再分发、专有程序。 (当然,如果您在重新分发 cygwin1.dll 本身时遵守 LGPL)。
不安装任何内容的唯一方法就是根本不存在文件。如果有一个文件,则必须将其放置在某个位置,并且满足安装的定义。在 Windows 上,如果您有一个依赖于
.dll
的.exe
文件,您只需确保将它们放入同一目录即可。如果程序太不重要以至于无法保证开发完整的安装程序,则可以通过将它们放入.zip
文件中来轻松满足此要求。您的老师将您的
.zip
文件解压到桌面上或下载目录中。应该会出现一个文件夹,该文件夹中包含您的程序和dll
。可以调用程序并加载dll
;不用想也知道。Shipping an
.exe
with an cluster of.dll
files is the norm on Windows.If you use Microsoft Visual Studio, your program will also need be shipped with some libraries from the Visual Studio Redistributable Run-Time. (Unless you link it statically.) Most major applications on Windows have installation directories chock full of
dll
files, and won't run without them.In the middle of 2016, the Cygwin project changed the licensing from GPL to LGPL. This means you can link programs with to
cygwin1.dll
and redistribute them, even if those programs have a license that is not compatible with the regular GPL, such as closed-source, non-freely-redistributable, proprietary programs. (If you otherwise comply with the LGPL in regard to how you are redistributingcygwin1.dll
itself, of course).The only way not to install anything is not to have a file at all. If there is a single file it has to be put somewhere, and that meets the definition of installation. On Windows, if you have a
.exe
file that depends on a.dll
, all you have to ensure is that they are put into the same directory. This requirement can be met as easily as by putting them into a.zip
file, if the program is too unimportant to warrant developing a full blown installer.Your teacher unzips your
.zip
file on their Desktop, or in their Downloads directory. A folder should appear, and in that folder is your program and thedll
. The program can be invoked and loads thedll
; no brainer.