开发者

JPA and database in a single jar

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?


  • 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.

JPA and database in a single jar

  • 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜