我正在尝试使用JPA 2.0创建一个Google App Engine - GAE,我已经按照我需要的所有内容,将正确的jar放在classpath中并确保我的实体得到增强。 但是我在创建EntityManager时遇到了问题。
我的persistence.xml如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
</properties>
</persistence-unit>
</persistence>
我的Datanuclues pom dependecy看起来像这样:
<datanucleus.version>3.1.1</datanucleus.version>
<!-- DN -->
<dependency>
<groupId>com.google.appengine.orm</groupId>
<artifactId>datanucleus-appengine</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jpa</artifactId>
<version>${datanucleus.version}</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>${datanucleus.version}</version>
</dependency>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>${datanucleus.version}</version>
<configuration>
<api>JPA</api>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
我明白了:
C:\dev\projects\org\me\workspace\lottoshop>mvn gae:run
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building GWT Maven Archetype
[INFO] task-segment: [gae:run]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing gae:run
[INFO] Preparing gae:unpack
[WARNING] Removing: unpack from forked lifecycle, to prevent recursive invocation.
[INFO] No goals needed for project - skipping
[INFO] artifact org.datanucleus:datanucleus-enhancer: checking for updates from nexus-releases-repository
[WARNING] repository metadata for: 'artifact org.datanucleus:datanucleus-enhancer' could not be retrieved from repository: nexus-releases-repository due to an error: Error transferring file: nexus.tatis.com
[INFO] Repository 'nexus-releases-repository' will be blacklisted
[INFO] artifact org.datanucleus:datanucleus-enhancer: checking for updates from nexus-snapshots-repository
[WARNING] repository metadata for: 'artifact org.datanucleus:datanucleus-enhancer' could not be retrieved from repository: nexus-snapshots-repository due to an error: Error transferring file: nexus.tatis.com
[INFO] Repository 'nexus-snapshots-repository' will be blacklisted
[INFO] [gae:unpack {execution: start-gae}]
[INFO] Found appengine-java-sdk 1.7.5.
[INFO] [gwt:i18n {execution: default}]
[INFO] [gwt:generateAsync {execution: default}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\WEB-INF\classes
[INFO] [war:exploded {execution: default}]
[INFO] Exploding webapp
[INFO] Assembling webapp [lottoshop] in [C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\dev\projects\org\me\workspace\lottoshop\src\main\webapp]
[INFO] Webapp assembled in [225 msecs]
[INFO] artifact org.ow2.asm:asm: checking for updates from nexus-plugin-repository
[WARNING] repository metadata for: 'artifact org.ow2.asm:asm' could not be retrieved from repository: nexus-plugin-repository due to an error: Error transferring file: nexus.tatis.com
[INFO] Repository 'nexus-plugin-repository' will be blacklisted
[INFO] [datanucleus:enhance {execution: default}]
[INFO] DataNucleus Enhancer (version 3.1.1) : Enhancement of classes
DataNucleus Enhancer completed with success for 1 classes. Timings : input=208 ms, enhance=24 ms, total=232 ms. Consult the log for full details
[ERROR] --------------------
[ERROR] Standard error from the DataNucleus tool + org.datanucleus.enhancer.DataNucleusEnhancer :
[ERROR] --------------------
[ERROR] Mar 13, 2013 11:48:42 PM org.datanucleus.enhancer.DataNucleusEnhancer <init>
INFO: DataNucleus Enhancer for API "JPA"
Mar 13, 2013 11:48:42 PM org.datanucleus.enhancer.DataNucleusEnhancer main
INFO: DataNucleus Enhancer (version 3.1.1) : Enhancement of classes
Mar 13, 2013 11:48:42 PM org.datanucleus.metadata.MetaDataManager loadFiles
WARNING: Metadata file -enhancerName not found in CLASSPATH
Mar 13, 2013 11:48:42 PM org.datanucleus.metadata.MetaDataManager loadFiles
WARNING: Metadata file ASM not found in CLASSPATH
Mar 13, 2013 11:48:43 PM org.datanucleus.enhancer.asm.ASMClassEnhancer enhance
INFO: Class "co.za.fwc.webapp.lottery.shared.dto.Player" is already enhanced.
Mar 13, 2013 11:48:43 PM org.datanucleus.enhancer.DataNucleusEnhancer addMessage
INFO: DataNucleus Enhancer completed with success for 1 classes. Timings : input=208 ms, enhance=24 ms, total=232 ms. Consult the log for full details
[ERROR] --------------------
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\dev\projects\org\me\workspace\lottoshop\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] [gwt:compile {execution: default}]
[INFO] auto discovered modules [co.za.fwc.lottery.lottoshop.LottoShop, com.extjs.gxt.samples.resources.Resources]
[INFO] com.extjs.gxt.samples.resources.Resources has no EntryPoint - compilation skipped
[INFO] Compiling module co.za.fwc.lottery.lottoshop.LottoShop
[INFO] Validating units:
[INFO] Ignored 81 units with compilation errors in first pass.
[INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO] Computing all possible rebind results for 'com.google.gwt.useragent.client.UserAgentAsserter'
[INFO] Rebinding com.google.gwt.useragent.client.UserAgentAsserter
[INFO] Checking rule <generate-with class='com.google.gwt.editor.rebind.SimpleBeanEditorDriverGenerator'/>
[INFO] [WARN] Detected warnings related to 'com.google.gwt.editor.client.SimpleBeanEditorDriver'. Are validation-api-<version>.jar and validation-api-<version>-sources.jar on the classpath?
[INFO] Specify -logLevel DEBUG to see all errors.
[INFO] [WARN] Unknown type 'com.google.gwt.editor.client.SimpleBeanEditorDriver' specified in deferred binding rule
[INFO] Compiling 6 permutations
[INFO] Compiling permutation 0...
[INFO] Process output
[INFO] Compiling
[INFO] Compiling permutation 3...
[INFO] Process output
[INFO] Compiling
[INFO] Compiling permutation 1...
[INFO] Process output
[INFO] Compiling
[INFO] Compiling permutation 2...
[INFO] Compiling permutation 4...
[INFO] Compiling
[INFO] Compiling permutation 5...
[INFO] Compile of permutations succeeded
[INFO] Linking into C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\LottoShop
[INFO] Link succeeded
[INFO] Compilation succeeded -- 37.226s
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp [lottoshop] in [C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\dev\projects\org\me\workspace\lottoshop\src\main\webapp]
[INFO] Webapp assembled in [194 msecs]
[INFO] Building war: C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT.war
[INFO] [gae:run {execution: default-cli}]
Mar 13, 2013 11:49:25 PM com.google.apphosting.utils.config.EarHelper logNotAnEar
INFO: Directory 'C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT' is not an EAR directory. File C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\appengine-application.xmlappengine-application.xml not detected.
Mar 13, 2013 11:49:25 PM com.google.apphosting.utils.config.EarHelper logNotAnEar
INFO: Directory 'C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT' is not an EAR directory. File C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\appengine-application.xmlappengine-application.xml not detected.
Mar 13, 2013 11:49:25 PM com.google.apphosting.utils.config.EarHelper logNotAnEar
INFO: Directory 'C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT' is not an EAR directory. File C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\appengine-application.xmlappengine-application.xml not detected.
Mar 13, 2013 11:49:25 PM com.google.apphosting.utils.config.EarHelper logNotAnEar
INFO: Directory 'C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT' is not an EAR directory. File C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\appengine-application.xmlappengine-application.xml not detected.
Mar 13, 2013 11:49:25 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\WEB-INF/appengine-web.xml
2013-03-13 23:49:25.382:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
Mar 13, 2013 11:49:25 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
INFO: Successfully processed C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\WEB-INF/web.xml
Mar 13, 2013 11:49:25 PM com.google.appengine.tools.development.SystemPropertiesManager setSystemProperties
INFO: Overwriting system property key 'java.util.logging.config.file', value 'C:\Users\babajide.agbebiyi\.m2\repository\com\google\appengine\appengine-java-sdk\1.7.5\appengine-java-sdk-1.7.5\config\sdk\logging.properties' with value 'WEB-INF/logging.properties' from 'C:\dev\projects\org\me\workspace\lottoshop\target\lottoshop-0.0.1-SNAPSHOT\WEB-INF\appengine-web.xml'
2013-03-13 23:49:25.757:INFO::jetty-6.1.x
2013-03-13 23:49:26.919:INFO::Started SelectChannelConnector@127.0.0.1:8080
Mar 13, 2013 9:49:26 PM com.google.appengine.tools.development.AbstractServer startup
INFO: Server default is running at http://localhost:8080/
Mar 13, 2013 9:49:26 PM com.google.appengine.tools.development.AbstractServer startup
INFO: The admin console is running at http://localhost:8080/_ah/admin
Mar 13, 2013 9:49:26 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: Dev App Server is now running
Mar 13, 2013 9:49:52 PM com.google.appengine.tools.development.LocalResourceFileServlet doGet
WARNING: No file found for: /favicon.ico
Mar 13, 2013 9:49:53 PM org.datanucleus.api.jpa.JPAEntityManagerFactory <init>
WARNING: No META-INF/persistence.xml files were found in the CLASSPATH of the current thread!
Mar 13, 2013 9:49:53 PM org.datanucleus.api.jpa.JPAEntityManagerFactory <init>
WARNING: No persistence unit of name "transactions-optional" is found in the CLASSPATH of the current thread!
Mar 13, 2013 9:49:53 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.String co.za.fwc.lottery.lottoshop.client.LottoService.greetServer(java.lang.String) throws java.lang.IllegalArgumentException' threw an unexpected exception: java.lang.ExceptionInInitializerError
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:389)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:409)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
at co.za.fwc.lottery.lottoshop.server.LottoServiceImpl.greetServer(LottoServiceImpl.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 38 more
Caused by: javax.persistence.PersistenceException: No persistence providers available for "transactions-optional" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:182)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
at co.za.fwc.lottery.lottoshop.shared.EMF.<clinit>(EMF.java:6)
... 49 more
更新:添加图片以显示我有persistence.xml
答案 0 :(得分:4)
我个人会阅读错误消息。 JPA非常清楚地定义了persistence.xml
必须在哪里,并且它不存在。
“在CLASSPATH中找不到META-INF / persistence.xml文件 当前线程!“
答案 1 :(得分:1)
我必须将persistence.xml移动到WEB-INF/classes/META-INF
for android studio中的app引擎后端应用程序。
projectdir/backend/src/main/webapp/WEB-INF/classes/META-INF/persistence.xml
答案 2 :(得分:0)
使用持久性api时请记住。 在META-INF中,有两个名为:
的文件如果您正在使用持久性api,那么您可以通过在jdoconfig.xml文件中添加块注释来消除此错误