JPA and database in a single jar

亡梦爱人 提交于 2019-12-23 18:46:44

问题


I created an app which uses JPA and MySQL. Now I like to create simple desktop application out of it (eg a simple jar would be best). Two questions:

  • What's the easiest way to get a project including all jars it depends on out of eclipse in a simple jar?
  • Can I use a database like sqlite or derby which requires no installation (eg can be included in the jar) for JPA?

回答1:


  • What's the easiest way to get a project including all jars it depends on out of eclipse in a simple jar?

Create a Java Project, write code, rightclick project, choose Export > Runnable JAR file and finally choose from the Library handling options.

  • Can I use a database like sqlite or derby which requires no installation (eg can be included in the jar) for JPA?

Yes, you can do that. Just include and specify the suitable JDBC driver.




回答2:


Yes, there are a number of "embeddable" databases that require no separate server process. That solves part of the problem.

Another part of the problem is that all your 3rd party code (the JPA engine, the database and maybe more) sits in yet other jars. If you really truly want just a single jar, you'll have to mung all those jars together into one. There are some programs that accomplish this, I seem to remember the name "bigjar" but Google isn't turning up any good leads for it. However, you can easily do the equivalent yourself using just ant. There's a big discussion (with sample code) in this Sun forum thread.



来源:https://stackoverflow.com/questions/3289942/jpa-and-database-in-a-single-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!