如何分发我的 Java 程序,以便通过双击单个文件来运行它? [英] How to distribute my Java program so that it is runnable by double-clicking a single file?

查看:23
本文介绍了如何分发我的 Java 程序,以便通过双击单个文件来运行它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Java 富客户端桌面应用程序.我想在工作中的一些计算机上分发,但我以前从未做过这样的事情.人们在我的工作场所不太精通计算机,而且由于这是一份学生的工作,我不会在那里待太久,如果我能让我的程序易于运行,当人们翻倍时,我希望它可以运行- 点击它.

I have a Java rich client desktop app. that I want to distribute on some computers at work, but I've never done something like this before. People aren't too computer-savy at my workplace and since it is a student job, I won't be there for much longer and I'd like it if I could make my program easy to run by making it runnable when people double-click on it.

我也不想手动安装 JRE 来运行它.基本上,我想知道的是如何通过双击使我的java应用程序可以轻松运行(即使它仅在Windows上,也可以).我很确定我需要同时打包正确的 JRE 版本,但我不知道这样做的正确方法是什么.

I also don't want to have to manually install a JRE to have it run. Basically, what I'd like to know is how to make my java application runnable easily by double-clicking (even if it's only on windows, it's okay). I'm pretty sure I'm going to need to package the correct JRE version alongside, but I don't know what's the correct way of doing this.

我在一些网站上读到你不应该将 JRE 与你的程序一起打包,因为它让人们有多个不同的版本,其中一些已经过时,并且会导致安全问题,但这在这种情况下不是问题,因为将要运行我的应用程序的计算机没有连接到互联网,无论如何也只是用来运行这个程序.

I read on some sites that you should not package a JRE along with your program because it makes people have multiple different versions, some of which are outdated, and it causes security issues, but this is not a problem in this case since the computers that are going to run my application are not connected to the internet and are only used to run this program anyway.

有点相关的问题:由于我的应用程序当前是一个 Eclipse 项目,我使用相对路径(例如:png).

Somewhat related question: Since my application is currently an Eclipse project, I get my resources such as icons, images, SQLite database (for read and write), etc. using relative paths (e.g.: img/test.png).

我是否需要更改任何这些路径才能让它们在打包后继续工作?

Am I going to have to change any of those paths to have them keep working even while packaged?

推荐答案

您要查找的是 JAR 文件.在 Eclipse 中,制作 Jar 文件非常容易.具体来说,您需要右键单击您的项目,转到导出",然后选择Runnable Jar".小心文件夹的路径.您可能需要在 Jar 文件旁边保留一个资源文件夹.您可能需要提供一些更具体的信息才能得到确切的答案.通常,Resources 文件夹与 JAR 文件位于同一位置(在您计算机上的同一文件夹中).

What you're looking for is a JAR file. In eclipse, it's quite easy to make a Jar file. Specifically, you'll want to right click on your project, go to Export, and then select "Runnable Jar." Be careful with paths to folders. You may need to keep a resources folder next to the Jar file. You may need to provide some more specifics to get an exact answer on that. Typically, a Resources folder is located in the same spot as the JAR file (in the same folder on your computer).

这篇关于如何分发我的 Java 程序,以便通过双击单个文件来运行它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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