如何分发我的Java程序,以便双击单个文件可以运行? [英] How to distribute my Java program so that it is runnable by double-clicking a single file?
问题描述
我也不想手动安装一个JRE让它运行。基本上,我想知道的是如何使我的java应用程序通过双击轻松地运行(即使只在Windows上,没关系)。我很确定我需要包装正确的JRE版本,但我不知道这样做的正确方法。
我读了在某些网站上,您不应该将JRE与程序一起打包,因为它使人们有多个不同的版本,其中一些版本过时,导致安全问题,但这不是一个问题,因为这些计算机正在进行运行我的应用程序没有连接到互联网,只用于运行这个程序。
有点相关的问题:由于我的应用程序目前是一个Eclipse项目,我得到我的资源,如图标,图像,SQLite数据库(用于读取和写入)等使用相对路径(例如: img / test.png
)。
我将不得不更改任何这些路径,让他们在打包时保持工作?
您要查找的是JAR文件。在日食中,制作一个Jar文件很容易。具体来说,您需要右键单击项目,转到导出,然后选择Runnable Jar。小心文件夹的路径。您可能需要在Jar文件旁边保留资源文件夹。您可能需要提供一些更详细的信息才能得到确切的答案。通常,资源文件夹位于与JAR文件相同的位置(与计算机相同的文件夹中)。
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.
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.
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.
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?
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屋!