我正在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。
- 6月前1 #
- 6月前2 #
在MATLAB中使用Java時,我经常遇到動態類路徑的問题.解決方法是使用
classpath.txt
到目前為止已经解決了任何問题.應對不同的環境(例如測試和生产)会匯致多个
classpath.txt
MATLAB開始目錄中的檔案.使用不同的MATLAB版本会為classpath.txt
的數量增加另一个乘數 週圍的檔案.ClassPathHacker.java是將動態類和jar檔案添加到static類路徑的選項.使用這種方法,無需觸摸
classpath.txt
不再.您的Java類路徑配置可以保留在預期的位置 . - 6月前3 #
這只是有關靜態和動態類路徑的答案的後續內容.這是一个函式,可让您诊斷从Matlab中將Java類載入到的位置,以及是否對類定義进行了任何掩盖,這可能就是為什麼它對為您排序很敏感.您可能還会看到其他碰撞; Matlab至少附帶了dom4j.jar和commons-collections.jar,但我不知道什麼版本。
startup.m
- 6月前4 #
確保您的類路徑上有一个JPA提供程式jar(例如eclipselink.jar)。
- 6月前5 #
您绝對確定正確拼寫了持久性單元的名稱 在呼叫中:
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。