正如here所述,IDEA在单元测试运行期间将jdoconfig.xml添加到类路径两次。有人可以建议解决这个问题吗?
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java -Dgwt.args=-gen /Users/jgc/Library/Caches/IntelliJIDEA9M1/gwt/recipes.recipesea699bb7/Recipes.4dd34334/test/gen -out /Users/jgc/Library/Caches/IntelliJIDEA9M1/gwt/recipes.recipesea699bb7/Recipes.4dd34334/test/www -Dfile.encoding=MacRoman -classpath /Users/jgc/gwt-versions/gwt-mac-1.7.0/gwt-dev-mac.jar:/Users/jgc/Documents/beanstalk/recipes/test:/Users/jgc/Documents/beanstalk/recipes/src:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/deploy.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/dt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/javaws.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/management-agent.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/plugin.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/sa-jdi.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/alt-rt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/charsets.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/dt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/jconsole.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/management-agent.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/../Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/ext/apple_provider.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/ext/dnsns.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/ext/localedata.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/ext/sunjce_provider.jar:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/ext/sunpkcs11.jar:/Users/jgc/Documents/beanstalk/recipes/out/test/Recipes:/Users/jgc/Documents/beanstalk/recipes/out/production/Recipes:/Users/jgc/gwt-versions/gwt-mac-1.7.0/gwt-user.jar:/Applications/IntelliJ IDEA 9.0M1.app/lib/javaee_6.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/appengine-api-1.0-sdk-1.2.5.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/geronimo-jpa_3.0_spec-1.1.1.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/datanucleus-jpa-1.1.5.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/datanucleus-core-1.1.5.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/appengine-api-labs-1.2.5.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/gwttheme.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/datanucleus-appengine-1.0.3.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/geronimo-jta_1.1_spec-1.1.1.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/jdo2-api-2.3-eb.jar:/Users/jgc/Documents/beanstalk/recipes/war/WEB-INF/lib/gwt-servlet.jar:/Users/jgc/appengine-java-sdk-1.2.5/lib:/Users/jgc/appengine-java-sdk-1.2.5/lib/appengine-tools-api.jar:/Applications/IntelliJ IDEA 9.0M1.app/lib/junit-4.6.jar:/Users/jgc/appengine-java-sdk-1.2.5/lib/impl/appengine-api-labs.jar:/Users/jgc/appengine-java-sdk-1.2.5/lib/impl/appengine-api.jar:/Users/jgc/appengine-java-sdk-1.2.5/lib/impl/appengine-api-stubs.jar:/Users/jgc/appengine-java-sdk-1.2.5/lib/impl:/Users/jgc/appengine-java-sdk-1.2.5/lib/impl/appengine-local-runtime.jar:/Applications/IntelliJ IDEA 9.0M1.app/lib/idea_rt.jar com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.jgc.recipes.server.RecipeDAOTest
java.lang.ExceptionInInitializerError
at com.jgc.recipes.server.RecipeDAO.persistRecipe(RecipeDAO.java:27)
at com.jgc.recipes.server.RecipeDAOTest.testFoo(RecipeDAOTest.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:91)
at org.junit.runner.JUnitCore.run(JUnitCore.java:159)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:43)
Caused by: javax.jdo.JDOFatalUserException: Duplicate PMF name "transactions-optional" found in file:/Users/jgc/Documents/beanstalk/recipes/src/META-INF/jdoconfig.xml and file:/Users/jgc/Documents/beanstalk/recipes/out/production/Recipes/META-INF/jdoconfig.xml.
at javax.jdo.JDOHelper.getNamedPMFProperties(JDOHelper.java:1300)
at javax.jdo.JDOHelper.getPropertiesFromJdoconfig(JDOHelper.java:1232)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1079)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:914)
at com.jgc.recipes.server.PMF.<clinit>(PMF.java:7)
... 20 more
Process finished with exit code 255
答案 0 :(得分:3)
目前您可以通过编程方式传递PersistenceManagerFactory的属性,因此不使用jdoconfig.xml文件,例如。
private static PersistenceManagerFactory pmfInstance;
static {
Map props = new HashMap();
props.put("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory");
props.put("javax.jdo.option.ConnectionURL", "appengine");
props.put("javax.jdo.option.NontransactionalRead", "true");
props.put("javax.jdo.option.NontransactionalWrite", "true");
props.put("javax.jdo.option.RetainValues", "true");
props.put("datanucleus.appengine.autoCreateDatastoreTxns", "true");
pmfInstance = JDOHelper.getPersistenceManagerFactory(props);
}
private PMF() {
}
public static PersistenceManagerFactory get() {
return pmfInstance;
}