简体   繁体   English

使用 MySQL DB 完成 Java 桌面应用程序后,如何创建安装程序?

[英]How to create installer once finished with Java Desktop Application with MySQL DB?

I have finished writing a Java Desktop application with a mySQL database.我已经完成了使用 mySQL 数据库编写 Java 桌面应用程序。 I want to make the application run outside netbeans and let it be installed on other computers.我想让应用程序在 netbeans 之外运行,并让它安装在其他计算机上。 I know about building the project and creating the runnable jar file, however this requires me to export the database itself to the other computer I want the application to run on.我知道如何构建项目并创建可运行的 jar 文件,但这需要我将数据库本身导出到我希望应用程序在其上运行的另一台计算机。 My question is two parts:我的问题是两个部分:

1)Is there a way I can create a setup file that also installs the database and the application together? 1)有没有办法可以创建一个安装文件,同时安装数据库和应用程序?

2)Also my database path is hard coded, does that mean I have to change the code every time I install my application for someone, what is the better way to do that? 2)我的数据库路径也是硬编码的,这是否意味着我每次为某人安装应用程序时都必须更改代码,有什么更好的方法呢?

Thanks谢谢

  1. Yes.是的。 You can use some setup builder, like InnoSetup, for example.您可以使用一些设置生成器,例如 InnoSetup。 Personally, however, I like giving my customers a zip file, which they extract wherever they like.然而,就我个人而言,我喜欢给我的客户一个 zip 文件,他们可以在他们喜欢的任何地方提取该文件。 The executable jar should be able to handle everything by itself (I like it where there is no need to install the software, just unpack and run).可执行文件 jar 应该能够自己处理所有事情(我喜欢它不需要安装软件,只需解压缩并运行)。
  2. If it is hardcoded, then yes (but, what do you mean by hardcoded ? path to file? ip address?).如果它是硬编码的,那么是的(但是,编码是什么意思?文件路径?ip 地址?)。 You should use properties or configuration files for paths and other external things your software depends on.您应该为您的软件所依赖的路径和其他外部事物使用属性或配置文件。 The software should read from those files.软件应该从这些文件中读取。 Upon startup check for presence of such file(s) - if missing, the user should be shown a window in which the config can be entered.启动时检查是否存在此类文件 - 如果缺少,应向用户显示 window ,可以在其中输入配置。

As for deploying MySQL with your code - consider using a server for that, so that your users are not forced to install MySQL, instead they connect to it over the net.至于使用您的代码部署 MySQL - 考虑为此使用服务器,这样您的用户就不会被迫安装 MySQL,而是通过网络连接到它。 If you need the database only for storing data locally, why not using SQLite or a similar, file-based db engine?如果您只需要在本地存储数据的数据库,为什么不使用 SQLite 或类似的基于文件的数据库引擎?

The above answers are just suggestions and more-less reflect the way I am thinking.以上答案只是建议,更多地反映了我的思维方式。 I would be happy to hear from someone with more experience.我很高兴听到有更多经验的人的来信。 Nonetheless, I hope the answers help a little:)尽管如此,我希望答案能有所帮助:)

I agree with Sorrow.我同意悲伤。

If I have to use MySQL, it is normally over the net since I don't want to allow my clients pass through the hazzles of installing MySQL themselves.如果我必须使用 MySQL,它通常是在网上,因为我不想让我的客户通过自己安装 MySQL 的麻烦。 If however you am stuck with using MySQL locally, investigate MySQL unattended installations + NSIS Installer.但是,如果您坚持在本地使用 MySQL,请调查 MySQL 无人值守安装 + NSIS 安装程序。

If you can use any db you want, I just use javadb/derby.如果你可以使用任何你想要的 db,我只使用 javadb/derby。 It comes bundled with most Java installations these days and if not all you need is to add a jar file to you application.如今,它与大多数 Java 安装捆绑在一起,如果不是全部,您只需将 jar 文件添加到您的应用程序。

As per 'hardcoding' paths, I really don't understand what you mean.根据“硬编码”路径,我真的不明白你的意思。 You really don't have 'paths' as it were, I am assuming what you mean is connection string.你真的没有'路径',我假设你的意思是连接字符串。 You don't have to hardcode your connection string, just put some parameters in a properties file and construct your connection string from them.您不必对连接字符串进行硬编码,只需将一些参数放入属性文件并从中构造连接字符串。

1) Is there a way I can create a setup file that also installs the database and the application together? 1)有没有办法可以创建一个安装文件,同时安装数据库和应用程序?

See my answer to Java based Standalone application .请参阅我对基于 Java 的独立应用程序的回答。

2) Also my database path is hard coded, does that mean I have to change the code every time I install my application for someone, what is the better way to do that? 2)我的数据库路径也是硬编码的,这是否意味着我每次为某人安装应用程序时都必须更改代码,更好的方法是什么?

Have the DB installer pop a JFileChooser to ask the user where they want to install the DB.让数据库安装程序弹出一个JFileChooser来询问用户他们想在哪里安装数据库。 Store that path using the JNLP API PersistenceService .使用 JNLP API PersistenceService存储该路径。 Here is my demo.这是我的演示。 of the PersistenceService .的 PersistenceService

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为Java应用程序以及在mysql中创建的数据库创建安装程序包 - How to create an installer package for java application along with database created in mysql 为 Java 桌面应用程序创建安装程序 - Creating an installer for Java desktop application 如何创建Java桌面应用程序? - How to create a Java desktop application? 如何为多平台安装java桌面应用程序? - How to make installer of java desktop application for multi-platform? 如何在单个安装程序中为Java EE Web应用程序创建安装程序? - How to create an installer for a Java EE Web application in a single installer? 如何为Java应用程序创建安装程序? - How do I create an Installer for a Java Application? 如何为Java Web应用程序创建安装程序 - How to create an installer for java web application Mac,Windows和Linux上的Java桌面应用程序安装程序 - Java Desktop Application Installer on Mac and Windows and Linux 如何在Java桌面应用程序中使用spring(transactional)和hibernate创建嵌入式H2 DB? - How to create emdedded H2 DB with spring(transactional) and hibernate in java desktop application? 如何创建Java桌面应用程序自动更新? - How create Java Desktop application autoupdate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM