如何将 .jar 转换为 .exe? [英] How can I convert a .jar to an .exe?

查看:26
本文介绍了如何将 .jar 转换为 .exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为微软将 .jar 转换为 .exe.是否有任何程序转换器?

I want to convert a .jar to an .exe for microsoft. Is there any program converter for this?

另外,如果有适用于 Mac 和 Linux 的产品,我也会很感激这些建议.

Also if there's one for Mac and Linux I would appreciate suggestions for those too.

推荐答案

Launch4j 适用于 Windows 和 Linux/Mac.但是,如果您运行的是 Linux/Mac,则有一种方法可以将您的 jar 嵌入到为您执行自动启动的 shell 脚本中,因此您只有一个可运行文件:

Launch4j works on both Windows and Linux/Mac. But if you're running Linux/Mac, there is a way to embed your jar into a shell script that performs the autolaunch for you, so you have only one runnable file:

exestub.sh:

#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt  0 -a -f "$0" ] && MYSELF="./$0"
JAVA_OPT=""
PROG_OPT=""
# Parse options to determine which ones are for Java and which ones are for the Program
while [ $# -gt 0 ] ; do
    case $1 in
        -Xm*) JAVA_OPT="$JAVA_OPT $1" ;;
        -D*)  JAVA_OPT="$JAVA_OPT $1" ;;
        *)    PROG_OPT="$PROG_OPT $1" ;;
    esac
    shift
done
exec java $JAVA_OPT -jar $MYSELF $PROG_OPT

然后你从你的 jar 中创建你的可运行文件:

Then you create your runnable file from your jar:

$ cat exestub.sh myrunnablejar.jar > myrunnable
$ chmod +x myrunnable

它的工作方式与 launch4j 的工作方式相同:因为 jar 具有 zip 格式,其标头是位于文件的末尾.你可以有任何你想要的头文件(二进制可执行文件,或者像这里的 shell 脚本)并运行 java -jar ,因为 是一个有效的 zip/jar 文件.

It works the same way launch4j works: because a jar has a zip format, which header is located at the end of the file. You can have any header you want (either binary executable or, like here, shell script) and run java -jar <myexe>, as <myexe> is a valid zip/jar file.

这篇关于如何将 .jar 转换为 .exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆