[英]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谢谢
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.