views:

45

answers:

2

Hi all

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?
A: 

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.

Carl Smotricz
with ant or maven
Redlab
Like which one, I'm trying to get sqlite to work with toplink.. but no luck so far..
Nils
First you have to get your project working in Eclipse. Then you pack everything you need into your jar and try to get it working again. The most common problems are with files and other resources, paths and classpaths that need some tweaking.
Carl Smotricz
+4  A: 
  • 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.

alt text

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

BalusC
Wow haven't seen this thx! Let's hope it really works with one click..
Nils
You're welcome.
BalusC
Hat tip and +1 to the far better answer. The makers of Eclipse slipped this new feature right by me, thanks!
Carl Smotricz
@Carl: IIRC it was in since Ganymede (2008), or maybe already since Europa (2007). It's a damn handy feature, yes :)
BalusC