用于启动 java 应用程序的小 exe

发布于 2024-10-30 05:00:59 字数 410 浏览 3 评论 0 原文

有些问题是这样的:如何将我的java应用程序打包成exe? 这不是我要问的。

我可以通过执行以下操作来启动我的应用程序:

java -jar myApp.jar 

效果很好(假设机器有 java 1.5.0 或 >)

现在我想要的是 myApp.exe 文件。

它会执行以下操作:

  1. 检查计算机上是否安装了 java 及其版本。 如果 java 不存在,则会提示一个对话框: “您需要安装java才能运行myApp” 就像 eclipse.exe 没有找到 java 时所做的那样。 然后它就会终止。
  2. 如果有java,则有效运行命令 javaw -jar app.jar 并生成进程。

有什么想法吗?

Some questions are like: How can I package my java app into an exe ?
This is not what I am going to ask.

I can launch my application by doing the following:

java -jar myApp.jar 

That works perfectly (Assuming the machine has java 1.5.0 or >)

Now what I was thinking of having is a myApp.exe file.

What it would do is the following:

  1. check if java is installed on the machine and its version.
    if java is not there it would prompt a dialog to say:
    "you need to install java to run myApp"
    exactly like eclipse.exe does if it does not find java.
    it would then terminate.
  2. if java is there, then effectively run the command
    javaw -jar app.jar and spawn the process.

any idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

初懵 2024-11-06 05:00:59

JSmooth 正是这样做的。

JSmooth does exactly that.

饮湿 2024-11-06 05:00:59

我使用 NSISLaunch4j.
NSIS 允许您根据需要使用一些向导窗口等创建安装脚本,Launch4j 允许您将可执行 jar 包装到 exe 文件中。
我已经使用这两种方法向 4000 个用户分发了 swing 应用程序。为了更精确,我必须在开始安装之前检查是否安装了 java 1.5 或更高版本。

I've done a similar thing using NSIS and Launch4j.
NSIS allows you to create a setup script as you want with some wizard windows etc., Launch4j allows you to wrap the executable jar into an exe file.
I've used both to distribute a swing application to 4000 users. For more precision, I had to check that java 1.5 or later was installed before starting the setup.

烟柳画桥 2024-11-06 05:00:59

像批处理脚本之类的东西不起作用?

@echo off

for /f %%j in ("java.exe") do (
    set JAVA_HOME=%%~dp$PATH:j
)

if %JAVA_HOME%.==. (
    @echo java.exe not found
) else (
    java -jar myApp.jar
)

从这个问题:从批处理文件中发现Java安装在哪里?

Something like that batch script wouldn't work?

@echo off

for /f %%j in ("java.exe") do (
    set JAVA_HOME=%%~dp$PATH:j
)

if %JAVA_HOME%.==. (
    @echo java.exe not found
) else (
    java -jar myApp.jar
)

From this question: Discover from a batch file where is Java installed?

浪漫之都 2024-11-06 05:00:59

我很长时间没有回答这个问题。
我认为可以公平地说,没有这么简单的方法可以做到这一点。
JSmooth 看起来是一个很好的工具,但它的局限性很大。
Eclipse 已经编写了自己的解决方案,并且许多其他用 java 编写的解决方案都部署为 exe。

I left this question unanswered for a very long time.
I think it's fair to say that there is no such easy way to do so.
JSmooth looks like a good tool, but it's pretty limited.
Eclipse has written its own solution and so many other solutions written in java deployed as exe.

飘逸的'云 2024-11-06 05:00:59

假设你的应用程序。有一个 GUI 和你可以从网站上交付它..

1) 检查机器上是否安装了java及其版本。如果 java 不存在,则会提示一个对话框:“您需要安装 java 才能运行 myApp”,就像 eclipse.exe 在找不到 java 时所做的那样。然后它就会终止。

.. 使用 deployJava.js 确保存在特定的最低版本的 Java,那么..

2) 如果 java 存在,则有效运行命令 javaw -jar app.jar 并生成进程。

..使用 Java Web Start 启动应用程序。直接从网站上下来。 JWS 还提供许多其他简洁的功能,并且与任何支持 Java 的系统兼容。

Assuming your app. has a GUI & you can deliver it off a web site..

1) check if java is installed on the machine and its version. if java is not there it would prompt a dialog to say: "you need to install java to run myApp" exactly like eclipse.exe does if it does not find java. it would then terminate.

.. Use deployJava.js to ensure a particular minimum version of Java is present, then..

2) if java is there, then effectively run the command javaw -jar app.jar and spawn the process.

..use Java Web Start to launch the app. directly off the web site. JWS also offers many other neat features, and is compatible with any system that supports Java.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文