1

I wanted to know if it is possible to include an ObjectDB database file .odb in a runnable JAR.

The method:

EntityManagerFactory emf = Persistence.createEntityManagerFactory(path);

takes a String path as an argument and not a URL. This means that getResource() does not work. Neither do getResource.getPath() and getResource.toString() work, since they somehow show a distorted path name and during runtime the database file is created outside the jar file.

So I was wondering if it is possible for the .odb file to be created inside the JAR and be manipulated within the JAR.

fornit
  • 79
  • 1
  • 11

2 Answers2

1

Why can't you copy your resource to temporary folder using for instance:

FileUtils.copyURLToFile()

(http://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/FileUtils.html#copyURLToFile%28java.net.URL,%20java.io.File%29)? And then you can use file path to copy.

Temporary system folder for current user you can find by:

File tempDir = new File(System.getProperty("java.io.tmpdir"));
rsutormin
  • 1,629
  • 2
  • 17
  • 21
0

An ObjectDB database must be a file and cannot be a resource within a file.

Following the solution of rsutormin seems as the right way to go.

ObjectDB
  • 1,312
  • 8
  • 9