Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Using JPA in a JPF application

Davilovick
2007-09-06
2013-05-02
  • Davilovick
    Davilovick
    2007-09-06

    Hello!

    Im using JPF to develop an application that have a plugin architecture.

    The problem come when im trying to use JPA (Java Persistence API).
    To develop a JPA application they need to create a folder named META-INF, and a file named persistence.xml in this folder.

    In a normal java application we put the META-INF folder in the default directory, and all is OK, but in a JPF architecture, the situations is more confusing..

    Thanks to everyone!!

    PD: Sorry with my english, I'm spanish

     
    • Chris Ward
      Chris Ward
      2007-09-07

      The solution depends on how they try to load that file. If they load it from the classpath, then you can add that custom folder to the classpath using your plugin.xml file and then that library should be able to find it just fine. An example of adding a folder to the classpath is included below. Please note that you should only have one "runtime" section, so just add the "library" section below to your existing runtime section.

         <runtime>
            <library id="META-INF" path="META-INF/" type="resources">
               <export prefix="*" />
            </library>
         </runtime>

      Once you make that declaration, then just create the META-INF folder in the root of your plugin's folder.

      Chris

       
    • Davilovick
      Davilovick
      2007-09-10

      Thanks for the reply.

      The application load the META-INF/persistene.xml directly from the classpath.

      I think that JPF only load class files from the classpath, and trunk all files that no have .class extension..

       
    • Chris Ward
      Chris Ward
      2007-09-10

      JPF will in fact load files from the classpath besides .class files. That is what the type="resources" part does instead of the normal type="code". We are using this to load all types of files extensively in our application without any problems. If this does not work for you then there might be some other problem. Sometimes it can be tricky when working with 3rd party libraries, which might require you to set the current context class loader to be the JPF class loader for your plugin. You can get your plugin class loader from the PluginManager class and then use code like the following to set the context class loader before calling a 3rd party library:

      Thread.currentThread().setContextClassLoader(loader);

      Chris

       
    • Davilovick
      Davilovick
      2007-09-11

      THANKS, THANKS ...  IT WORKS.. XD

      I´ve changed the ContextClassLoader, and load correctly the META-INF/persistence.xml file.

      Thank you  very much..