2013-09-01 38 views
3

我是JavaEE的新手。java.lang.ClassFormatError:在類文件中非本機或抽象方法中的缺省代碼屬性javax/persistence/PersistenceException

我使用glassfish server 3.1在NETBEANS 7.2.1中創建了企業應用程序項目。

當我試圖清理並生成我獲得以下錯誤

An annotation processor threw an uncaught exception. 
Consult the following stack trace for details. 
java.lang.ClassFormatError: Absent Code attribute in method that is not native or   abstract in class file javax/persistence/PersistenceException 
at java.lang.ClassLoader.defineClass1(Native Method) 
at java.lang.ClassLoader.defineClass(ClassLoader.java:791) 
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) 
at java.net.URLClassLoader.access$100(URLClassLoader.java:71) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:423) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
at java.lang.Class.getDeclaredFields0(Native Method) 
at java.lang.Class.privateGetDeclaredFields(Class.java:2317) 
at java.lang.Class.getDeclaredField(Class.java:1899) 
at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.findDeclaredField(PrivilegedAccessHelper.java:62) 
at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getField(PrivilegedAccessHelper.java:216) 
at org.eclipse.persistence.internal.helper.Helper.getField(Helper.java:934) 
at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.initializeAttributes(InstanceVariableAttributeAccessor.java:100) 
at org.eclipse.persistence.mappings.DatabaseMapping.preInitialize(DatabaseMapping.java:1284) 
at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.preInitialize(AbstractDirectMapping.java:965) 
at org.eclipse.persistence.oxm.mappings.XMLDirectMapping.preInitialize(XMLDirectMapping.java:433) 
at org.eclipse.persistence.oxm.XMLDescriptor.preInitialize(XMLDescriptor.java:510) 
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:493) 
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:476) 
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:435) 
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:676) 
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:634) 
at org.eclipse.persistence.oxm.XMLContext$XMLContextState.<init>(XMLContext.java:830) 
at org.eclipse.persistence.oxm.XMLContext$XMLContextState.<init>(XMLContext.java:770) 
at org.eclipse.persistence.oxm.XMLContext.<init>(XMLContext.java:177) 
at org.eclipse.persistence.oxm.XMLContext.<init>(XMLContext.java:164) 
at org.eclipse.persistence.oxm.XMLContext.<init>(XMLContext.java:154) 
at org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceXMLMappings.createXMLContext(PersistenceXMLMappings.java:123) 
at org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.initPersistenceUnits(PersistenceUnitReader.java:168) 
at org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.<init>(PersistenceUnitReader.java:71) 
at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:376) 
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793) 
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722) 
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97) 
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029) 
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163) 
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108) 
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824) 
at com.sun.tools.javac.main.Main.compile(Main.java:439) 
at com.sun.tools.javac.main.Main.compile(Main.java:353) 
at com.sun.tools.javac.main.Main.compile(Main.java:342) 
at com.sun.tools.javac.main.Main.compile(Main.java:333) 
at com.sun.tools.javac.Main.compile(Main.java:76) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56) 
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1153) 
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:930) 
at org.netbeans.modules.java.source.ant.JavacTask.execute(JavacTask.java:145) 
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
at sun.reflect.GeneratedMethodAccessor498.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
at org.apache.tools.ant.Task.perform(Task.java:348) 
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
at sun.reflect.GeneratedMethodAccessor498.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
at org.apache.tools.ant.Task.perform(Task.java:348) 
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398) 
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
at sun.reflect.GeneratedMethodAccessor498.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
at org.apache.tools.ant.Task.perform(Task.java:348) 
at org.apache.tools.ant.Target.execute(Target.java:392) 
at org.apache.tools.ant.Target.performTasks(Target.java:413) 
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) 
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38) 
at org.apache.tools.ant.Project.executeTargets(Project.java:1251) 
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442) 
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
at sun.reflect.GeneratedMethodAccessor498.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
at org.apache.tools.ant.Task.perform(Task.java:348) 
at org.apache.tools.ant.Target.execute(Target.java:392) 
at org.apache.tools.ant.Target.performTasks(Target.java:413) 
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) 
at org.apache.tools.ant.Project.executeTarget(Project.java:1368) 
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) 
at org.apache.tools.ant.Project.executeTargets(Project.java:1251) 
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:283) 
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:541) 
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153) 

這是web.xml文件,如果它能夠幫助:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
<context-param> 
    <param-name>javax.faces.PROJECT_STAGE</param-name> 
    <param-value>Development</param-value> 
</context-param> 
<servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>/faces/*</url-pattern> 
</servlet-mapping> 
<session-config> 
    <session-timeout> 
     30 
    </session-timeout> 
</session-config> 
<welcome-file-list> 
    <welcome-file>faces/index.xhtml</welcome-file> 
</welcome-file-list> 

如果需要更多信息,請點它。

順便提一下,它構建得很好,但未能與另一條消息一起運行。而且我沒有改變任何事情。

早些時候運行失敗消息:

com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing  resource injection on managed bean shoplist 
at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:211) 

感謝所有幫助

+0

運行時類路徑被Java EE API JAR文件污染,沒有方法體。您是如何構建Web應用程序的?您是否下載了一個或多個源自完全任意容器的Java EE相關JAR文件,並將其放在webapp的'/ WEB-INF/lib'中以便修復Java EE API中的類的編譯錯誤? – BalusC

+0

你說得對。我從早期的嘗試中複製了web.xml以創建與Web應用程序相同的項目。 Netbeans是否有理由不爲企業應用程序項目創建web.xml文件?沒有必要嗎? 另外我從無法嘗試創建ejb類遠程接口的不必要的文件,我也刪除了它。我之前用它的遠程接口刪除了這個類,但是有些文件是自動創建的,我沒有注意到。 – qwerty

回答

6

嗯,我有同樣的問題,我使用NetBeans 7.3.1,當我在我的類庫我創建了一個門面數據庫得到了錯誤(使用JAva 7和Glassfish 4)

我遇到的問題是當您使用插入代碼和自動創建bean時,它添加了Java EE 6 API庫。我刪除了該庫並添加了Java EE 7 API。它爲我工作。

+0

在我的情況下,我將其更改爲'Java EE Web API6' – shareef

相關問題