我正在windows XP Pro SP3上使用MATLAB R2007b,Java 1.6 SE,Eclipse Helios和MySql 5。
我正在尝试创建一个使用JPA批注来访问MySql 5数据库的类库.这个想法是MATLAB脚本实例化了这些Java对象,这些Java对象提供了用于访问数据库的API。
我可以创建带注释的类,该类可在Eclipse中运行(即JUnit测试).我可以将代码导出到jar中,然后从命令提示符下运行它。
我使用javaaddpath()更新了MATLAB Java类路径.我可以在MATLAB中实例化我的Class程.但是,当我调用init()来调用javax.persistence.Persistence.createEntityManagerFactory()时,我会感到恐惧
"没有EntityManager的持久性提供程序"
此错误通常意味着persistence.xml文件不在正确的位置.但这一定是因为我的jar从命令行运行.将META-INF文件夹添加到MATLAB java类路径中无济于事.不论是否添加META-INF,也都不会提取jar并将提取的文件夹结构添加到类路径中。
有没有人有想法,或者没有? 有没有人在任何版本的MATLAB中做到这一点。
谢谢。
-reilly。
- 2021-1-101 #
- 2021-1-102 #
在MATLAB中使用Java时,我经常遇到动态类路径的问题.解决方法是使用
classpath.txt
到目前为止已经解决了任何问题.应对不同的环境(例如测试和生产)会导致多个
classpath.txt
MATLAB开始目录中的文件.使用不同的MATLAB版本会为classpath.txt
的数量增加另一个乘数 周围的文件.ClassPathHacker.java是将动态类和jar文件添加到static类路径的选项.使用这种方法,无需触摸
classpath.txt
不再.您的Java类路径配置可以保留在预期的位置 . - 2021-1-103 #
这只是有关静态和动态类路径的答案的后续内容.这是一个函数,可让您诊断从Matlab中将Java类加载到的位置,以及是否对类定义进行了任何掩盖,这可能就是为什么它对为您排序很敏感.您可能还会看到其他碰撞; Matlab至少附带了dom4j.jar和commons-collections.jar,但我不知道什么版本。
startup.m
- 2021-1-104 #
确保您的类路径上有一个JPA提供程序jar(例如eclipselink.jar)。
- 2021-1-105 #
您绝对确定正确拼写了持久性单元的名称 在呼叫中:
function whereisjavaclassloadingfrom(ClassName) %WHEREISJAVACLASSLOADINGFROM Show where a Java class is loaded from % % whereisjavaclassloadingfrom(ClassName) % % Shows where a Java class is loaded from in this Matlab session's JVM. % This is for diagnosing Java class load problems, such as classpath % ordering issues, seeing if a class of a given name is included in an % unexpected JAR file, etc. % % Displays output to console. % % Examples: % % whereisjavaclassloadingfrom('java.util.HashMap') % whereisjavaclassloadingfrom('com.ldhenergy.etools.MxUtil') % whereisjavaclassloadingfrom('com.google.common.collect.Maps') % whereisjavaclassloadingfrom('org.apache.commons.math.complex.Complex') % Use javaArray to get Class object without having to instantiate. This % lets it work with objects that have private or non-zero-arg constructors, % and avoids side effects of object construction. % (Would use java.lang.Class.forName(), because that's a more direct way of % doing this, but it doesn't work for stuff on the dynamic classpath.) ja = javaArray(ClassName,1); klass = ja.getClass().getComponentType(); klassLoader = klass.getClassLoader(); if isempty(klassLoader) % JVM used null to represent the "bootstrap" class loader % I think that's the same as the "system" class loader klassLoader = java.lang.ClassLoader.getSystemClassLoader(); end klassLoaderStr = char(klassLoader.toString()); klassFilePath = [strrep(ClassName, '.', '/') '.class']; try % This logic assumes that the classes exist as files in the class % loader. It's a valid assumption for mainstream class loaders, % including the one's I've seen with Matlab. klassUrl = klassLoader.getResource(klassFilePath); if isempty(klassUrl) klassUrlStr = ''; else klassUrlStr = char(klassUrl.toString()); end catch err klassUrlStr = sprintf('ERROR: %s', err.message); end % Get all locations, to reveal masked definitions urls = enumeration2array(klassLoader.getResources(klassFilePath)); disp(sprintf('Version: %s\nClass: %s\nClassLoader: %s\nURL: %s', version,... char(klass.getName()), klassLoaderStr, klassUrlStr)); if numel(urls) > 1 disp('Class is masked:'); for i = 1:numel(urls) disp(sprintf('URL %d: %s', i, char(urls(i)))); end end %% function out = enumeration2array(jenum) tmp = {}; while jenum.hasMoreElements() tmp{end+1} = jenum.nextElement(); end out = [tmp{:}];
那也会给你同样的错误.名称区分大小写。
javax.persistence.Persistence.createEntityManagerFactory(String puName)
相关问题
- java:JAXB将循环引用映射到XMLjavajpaxmlserializationjaxb2021-01-11 22:25
- java:Hibernate / JPA-注释bean方法与字段javahibernateormjpa2021-01-11 11:28
- java:Spring-Data-Jpa存储库-实体列名称下划线javajpaspringdatarepositoryspringdatajpa2021-01-11 07:57
- java:注释以过滤@OneToMany关联的结果javahibernatejpajointable2021-01-11 07:26
好吧,我找到了"答案".在我看到有关MATLAB"动态"和"静态" cp的差异的帖子之前的某个地方. "静态" cp是在启动时加载的文本文件. "动态" cp是在运行时加载的,通常您可以通过m脚本调用对其进行操作.那就是我想做的。
所以我将jars添加到了动态路径中,但是它没有用。
我将它们添加到静态路径的末尾,并得到了DIFFERENT错误,该错误似乎与XML解析有关.进步!
然后我将jars添加到静态路径的BEGINNING中,并且可以正常工作。
引用巴特·辛普森的话:Craptackular。
感谢您的所有想法.问我一个C#问题,这样我就可以回报...
-reilly。