Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JPA Class for MATLAB

I'm using MATLAB R2007b, Java 1.6 SE, Eclipse Helios, and MySql 5 on Windows XP Pro SP3.

I'm trying to create a class library that uses JPA annotations to access a MySql 5 database. The idea is that the MATLAB script instantiates these Java objects, which provide an API for accessing the DB.

I can create my annotated classes, which work within Eclipse (i.e. JUnit test). I can export the code to a jar, which I can run from a command prompt.

I update the MATLAB Java classpath using javaaddpath(). I can instantiate my class within MATLAB. But when I call my init(), which calls javax.persistence.Persistence.createEntityManagerFactory(), I get the dreaded

"No Persistence provider for EntityManager"

This error usually means that the persistence.xml file isn't in the right place. But it must be because my jar works from the command line. Adding the META-INF folder to the MATLAB java classpath doesn't help. Nor does extracting the jar and adding the extracted folder structure to the classpath, whether or not META-INF is added.

Does anyone have any ideas, nutty or not? Has anyone ever done this in any version of MATLAB.

Thanks.

-reilly.

like image 867
Reilly Avatar asked Dec 07 '10 12:12

Reilly


1 Answers

Well, I found "an answer." Somewhere before I saw a post about the difference in MATLAB's "dynamic" and "static" cp's. The "static" cp is a text file that is loaded at startup. The "dynamic" cp is loaded at runtime and you typically manipulate it with m-script calls. That's what I was trying to do.

So I added my jars to the dynamic path and it didn't work.

I added them to the end of the static path and got DIFFERENT errors, which seemed to pertain to the XML parsing. Progress!

Then I added my jars to the BEGINNING of the static path and it works.

To quote Bart Simpson: Craptackular.

Thanks for all your ideas. Ask me a C# question so I can reciprocate...

-reilly.

like image 98
Reilly Avatar answered Oct 10 '22 09:10

Reilly