完成 Java 项目,现在创建 jar 或 .exe 文件(带数据库)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18580731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:11:46  来源:igfitidea点击:

Finished Java project, now creating jar or .exe file (with Database)

javamysqldatabasenetbeansjar

提问by Tha.Poox

So, i've just finished a small java application, with database and stuff... I used Netbeans and Mysql, now i want to export my project so i can use it anywhere i want; any computer, even with no Mysql or Java installed! So, i've tried some programs like Launch4j or something... but the main problem is, even if i make the .exe file, what's gonna happen with the database? it's located in my PC, so if somebody try to use my application, he can't access to the database, so the application won't work...

所以,我刚刚完成了一个带有数据库和其他东西的小型 Java 应用程序......我使用了 Netbeans 和 Mysql,现在我想导出我的项目,以便我可以在任何我想要的地方使用它;任何计算机,即使没有安装 Mysql 或 Java!所以,我已经尝试了一些程序,比如 Launch4j 或其他东西……但主要的问题是,即使我制作了 .exe 文件,数据库会发生什么?它位于我的 PC 中,因此如果有人尝试使用我的应用程序,他将无法访问数据库,因此该应用程序将无法运行...

In other words...What is the solution that i can use to like "Combine" the database with the application, if it is possible? or create the .exe file with the database... I hope that my problem is clear, and thank you for your answers :)

换句话说......如果可能的话,我可以用来将数据库与应用程序“结合”的解决方案是什么?或者用数据库创建.exe文件...我希望我的问题很清楚,谢谢你的回答:)

回答by ash

In order to get a database built-in to the application, consider HSQLDB, which is an in-memory database.

为了将数据库内置到应用程序中,请考虑 HSQLDB,它是一种内存数据库。

http://hsqldb.org/

http://hsqldb.org/

It can run entirely in the JVM without any external resources.

它可以完全在 JVM 中运行,无需任何外部资源。

回答by Tyler

When you were programming in netbeans did you include the database within netbeans? Here is a guide on how to do this.

当您在 netbeans 中编程时,是否将数据库包含在 netbeans 中?这是有关如何执行此操作的指南。

https://netbeans.org/kb/docs/ide/mysql.html

https://netbeans.org/kb/docs/ide/mysql.html

Also here is a second guide on how to Packaging and Distributing Java Desktop Applications

另外这里是关于如何打包和分发 Java 桌面应用程序的第二个指南

https://netbeans.org/kb/docs/java/javase-deploy.html

https://netbeans.org/kb/docs/java/javase-deploy.html

I hope these help.

我希望这些有帮助。

If not just go over your step you took to build the app.

如果不只是回顾一下您构建应用程序所采取的步骤。

回答by micha

You can look at MySQL Connector/MXJto embed your mysql database in your application.

您可以查看MySQL Connector/MXJ以将您的 mysql 数据库嵌入到您的应用程序中。

But be aware that this package is no longer under active development:

但请注意,此软件包不再处于积极开发状态:

Due to very low demand, MySQL has stopped development and support for Connector/MXJ. Source and binaries for previously released versions will continue to be available from archives.

由于需求非常低,MySQL 已停止开发和支持 Connector/MXJ。以前发布的版本的源代码和二进制文件将继续从档案中获得。

An alternative solutation would be using another database like SQLite, H2or HSQLDB

另一种解决方案是使用另一个数据库,如SQLiteH2HSQLDB

回答by Peter Goodheart

if you really want to give your users a good experience, I would suggest you implement a embedded database in your application instead.

如果你真的想给你的用户一个好的体验,我建议你在你的应用程序中实现一个嵌入式数据库。

Look at: http://www.h2database.com/

看:http: //www.h2database.com/

It's free and open source and I use it heavily myself. It supports embedded (where it creates flat database files on the computer), in-memory, and server-mode, where you have the possibility of letting multiple-applications share the same database.

它是免费和开源的,我自己也大量使用它。它支持嵌入式(在计算机上创建平面数据库文件)、内存和服务器模式,您可以让多个应用程序共享同一个数据库。

It's just a jar file you include in your application, and then the users wont have to install neither MySQL, have access to MySQL on a network drive or need other database software installed. (depending on your requirements, it might also be a good idea to look into Hibernate, to have some more abstraction between the different RDBMS).

它只是您在应用程序中包含的一个 jar 文件,这样用户就不必安装 MySQL、可以在网络驱动器上访问 MySQL 或需要安装其他数据库软件。(根据您的要求,研究 Hibernate 也可能是一个好主意,以便在不同的 RDBMS 之间有更多的抽象)。

回答by raghav vishnoi

You can create an executable jar by exporting your project through eclipse. You can do this by following these steps:

您可以通过 eclipse 导出您的项目来创建一个可执行的 jar。您可以按照以下步骤执行此操作:

  • Right click on the Project
  • Export as Jar file
  • 右键单击项目
  • 导出为 Jar 文件