简体   繁体   English

提供启动MySQL的java应用程序(自包含应用程序)

[英]Deliver a java application that starts MySQL (self-contained app)

I have a (for me complex) problem, but wil try to address only 1 issue in this thread. 我有一个(对我而言)复杂的问题,但是我会尝试解决这个问题中的1个问题。

I have a java application that has a MySQL database in the backend. 我有一个java应用程序,后端有一个MySQL数据库。

I want to be able to deliver the application along with the database preferebly via an installer (this is also a part I have not currently a solution). 我希望能够通过安装程序将数据库与数据库一起交付(这也是我目前还没有解决方案的一部分)。

Anyway the problem for now, is that my preference is that MySQL should not be installed as a service. 无论如何,现在的问题是我的偏好是MySQL不应该作为服务安装。
My reason is that I would prefer not to modify the machine, that my application will be deployed. 我的理由是我不想修改机器,我的应用程序将被部署。
I prefer to deliver a "self-contained" application. 我更喜欢提供“自包含”的应用程序。

So if MySQL is not installed as a service, then it must be started somehow. 因此,如果MySQL没有作为服务安装,那么它必须以某种方式启动。
I know that I can start MySQL as a standalone using: 我知道我可以使用以下单独启动MySQL:

mysqld --standalone --console

In this case a new command line window opens and MySQL runs (I used it so far during development/code testing). 在这种情况下,将打开一个新的命令行窗口并运行MySQL(我在开发/代码测试期间使用它)。

I don't know though how I can achieve the same effect once the application is deployed (and start MySQL via code at runtime). 我不知道在部署应用程序后如何实现相同的效果(并在运行时通过代码启动MySQL)。

I thought of using the Runtime and do something like: 我想过使用Runtime并执行以下操作:

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("PATH\\mysqld --standalone --console"); //PATH is of course the appropriate path to MySQL installation

But this does not seem to do anything. 但这似乎没有做任何事情。 It just remains hunging. 它只是在徘徊。

Ideally I would like to start MySQL and also not have a concole open . 理想情况下,我想启动MySQL 没有开放的concole

Is there a solution to my problem? 我的问题有解决方案吗?

Why do you want to make your life hard? 为什么你想让你的生活变得艰难? Don't use MySQL, instead use an Embedded Database , such as: 不要使用MySQL,而是使用嵌入式数据库 ,例如:

Check MySQL Connector/MXJ . 检查MySQL Connector / MXJ You can download it from here .It gives complete control over start and stop of database.Once you download and extract the zip, check ConnectorMXJObjectTestExample.java under 'src' folder. 您可以从这里下载它。它可以完全控制数据库的启动和停止。一旦下载并解压缩,请检查'src'文件夹下的ConnectorMXJObjectTestExample.java。 It will give you complete idea. 它会给你完整的想法。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM