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

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

问题描述

我想为Microsoft将.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的工作方式相同:因为一个罐子具有 zip格式,该标头是位于文件的 end 处.您可以具有所需的任何标头(二进制可执行文件或Shell脚本),然后运行java -jar <myexe>,因为<myexe>是有效的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天全站免登陆