使用带有MySQL DB的Java Desktop Application完成后如何创建安装程序?

时间:2023-02-04 06:31:39

I have finished writing a Java Desktop application with a mySQL database. I want to make the application run outside netbeans and let it be installed on other computers. 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. My question is two parts:

我已经用mySQL数据库编写了一个Java Desktop应用程序。我想让应用程序在netbeans外运行,并让它安装在其他计算机上。我知道构建项目和创建可运行的jar文件,但是这需要我将数据库本身导出到我希望运行应用程序的其他计算机上。我的问题是两部分:

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

3 个解决方案

#1


7  

  1. Yes. You can use some setup builder, like InnoSetup, for example. Personally, however, I like giving my customers a zip file, which they extract wherever they like. 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).
  2. 是。您可以使用一些设置构建器,例如InnoSetup。但就个人而言,我喜欢给我的客户一个zip文件,他们可以随意提取。可执行jar应该能够自己处理所有事情(我喜欢它,无需安装软件,只需解压缩并运行)。

  3. If it is hardcoded, then yes (but, what do you mean by hardcoded? path to file? ip address?). 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.
  4. 如果它是硬编码的,那么是(但是,硬编码是什么意思?文件的路径?IP地址?)。您应该使用属性或配置文件来处理软件所依赖的路径和其他外部事物。该软件应该从这些文件中读取。在启动时检查是否存在此类文件 - 如果缺少,则应向用户显示可以输入配置的窗口。

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. If you need the database only for storing data locally, why not using SQLite or a similar, file-based db engine?

至于使用您的代码部署MySQL - 考虑使用服务器,以便您的用户不必*安装MySQL,而是通过网络连接到它。如果您只需要数据库本地存储数据,为什么不使用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 :)

以上答案只是建议,更多地反映了我的思考方式。我很乐意听到有更多经验的人的发言。尽管如此,我希望答案有所帮助:)

#2


3  

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. If however you am stuck with using MySQL locally, investigate MySQL unattended installations + NSIS Installer.

如果我必须使用MySQL,它通常是通过网络,因为我不想让我的客户通过自己安装MySQL的难题。但是,如果您在本地使用MySQL,请调查MySQL无人值守安装+ NSIS安装程序。

If you can use any db you want, I just use 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.

如果你可以使用你想要的任何数据库,我只使用javadb / derby。它现在与大多数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.

按照“硬编码”路径,我真的不明白你的意思。你真的没有“路径”,我假设你的意思是连接字符串。您不必对连接字符串进行硬编码,只需将一些参数放在属性文件中并从中构造连接字符串即可。

#3


1  

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. Store that path using the JNLP API PersistenceService. Here is my demo. of the PersistenceService.

让数据库安装程序弹出JFileChooser,询问用户他们要安装数据库的位置。使用JNLP API PersistenceService存储该路径。这是我的演示。 PersistenceService。

#1


7  

  1. Yes. You can use some setup builder, like InnoSetup, for example. Personally, however, I like giving my customers a zip file, which they extract wherever they like. 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).
  2. 是。您可以使用一些设置构建器,例如InnoSetup。但就个人而言,我喜欢给我的客户一个zip文件,他们可以随意提取。可执行jar应该能够自己处理所有事情(我喜欢它,无需安装软件,只需解压缩并运行)。

  3. If it is hardcoded, then yes (but, what do you mean by hardcoded? path to file? ip address?). 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.
  4. 如果它是硬编码的,那么是(但是,硬编码是什么意思?文件的路径?IP地址?)。您应该使用属性或配置文件来处理软件所依赖的路径和其他外部事物。该软件应该从这些文件中读取。在启动时检查是否存在此类文件 - 如果缺少,则应向用户显示可以输入配置的窗口。

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. If you need the database only for storing data locally, why not using SQLite or a similar, file-based db engine?

至于使用您的代码部署MySQL - 考虑使用服务器,以便您的用户不必*安装MySQL,而是通过网络连接到它。如果您只需要数据库本地存储数据,为什么不使用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 :)

以上答案只是建议,更多地反映了我的思考方式。我很乐意听到有更多经验的人的发言。尽管如此,我希望答案有所帮助:)

#2


3  

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. If however you am stuck with using MySQL locally, investigate MySQL unattended installations + NSIS Installer.

如果我必须使用MySQL,它通常是通过网络,因为我不想让我的客户通过自己安装MySQL的难题。但是,如果您在本地使用MySQL,请调查MySQL无人值守安装+ NSIS安装程序。

If you can use any db you want, I just use 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.

如果你可以使用你想要的任何数据库,我只使用javadb / derby。它现在与大多数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.

按照“硬编码”路径,我真的不明白你的意思。你真的没有“路径”,我假设你的意思是连接字符串。您不必对连接字符串进行硬编码,只需将一些参数放在属性文件中并从中构造连接字符串即可。

#3


1  

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. Store that path using the JNLP API PersistenceService. Here is my demo. of the PersistenceService.

让数据库安装程序弹出JFileChooser,询问用户他们要安装数据库的位置。使用JNLP API PersistenceService存储该路径。这是我的演示。 PersistenceService。