如何分发我的 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).