ClassCastException: MyFilter cannot be cast to javax.servlet.Filter - jboss

I'm migrating an application to JBoss 7, where all dependencies were in "JBOSS_HOME/server/default/lib" (JBoss 4). I included the lib "servlet.jar" (javax.servlet. *), however, after setting a Global Module for JBoss 7 (modules.xml, standalone.xml, jboss-deployment-structure.xml in war files), libraries are loaded normally by JBoss.
When JBoss 7 tries to start the filters, I get following exception:
15:09:15,222 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/RegistrarValorDolar]] (MSC service thread 1-2) Exception starting filter cripto: java.lang.ClassCastException: cenpra.com.sigtec.business.utilities.SessionFilter cannot be cast to javax.servlet.Filter
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_15]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_15]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_15]
Trying to remove the library "servlet.jar" from Global Modules, in a try that the server loads it's own classes using an internal jar, I got a ClassNotFoundExceptionof javax.servlet.Filter class.
I want to use global modules, since I need to reuse a lot of libraries.

Your classpath is polluted with multiple different versioned javax.servlet.Filter classes. A class which is loaded by classloader X (e.g. the one responsible for container's internal classes) is not the same class when it's loaded by classloader Y (e.g. the one responsible for webapp's classes).
I included the lib "servlet.jar" (javax.servlet.)
This does at least not sound right. This is supposed to be already provided by the target servletcontainer (which is JBoss in your case). You should absolutely not provide servletcontainer-specific libraries along with the webapp in its /WEB-INF/lib folder. This would only end up in runtime classpath disaster because they get classloading precedence over the ones provided by the servletcontainer itself and thus conflicts with servletcontainer's internal classes which are in turn using servletcontainer's own classes.
Get rid of servletcontainer-specific libraries in /WEB-INF/lib folder.
This is a common starter's mistake in a careless attempt to fix/circumvent compilation errors on javax.servlet API which they face in their IDE. It should have been solved differently. To the point, you need to tell the IDE to associate the web project with the given target container. The IDE will then automatically do the necessary build path magic.
See also:
How do I import the javax.servlet API in my Eclipse project?

Related

Error during starting Jboss 4.3 while binding default hsql datasource

I get below error during JBoss start up.
[ServiceController] Problem starting service jboss:service=Hypersonic,database=localDB
java.lang.NoSuchMethodError: org.hsqldb.DatabaseURL.parseURL(Ljava/lang/String;ZZ)Lorg/hsqldb/persist/HsqlProperties;
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at org.jboss.jdbc.HypersonicDatabase.getConnection(HypersonicDatabase.java:768)
at org.jboss.jdbc.HypersonicDatabase.startStandaloneDatabase(HypersonicDatabase.java:618)
at org.jboss.jdbc.HypersonicDatabase.startService(HypersonicDatabase.java:564)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at com.sun.proxy.$Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
Background: I have added a new MS Access DB data source. For that, i am using ucanaccess library. Now, to bundle my code, i have created an executable uber jar which contains my main test program along with dependencies. Dependencies include following jars:
ucanaccess-4.0.1.jar
commons-lang-2.6.jar
commons-logging-1.1.3.jar
hsqldb-2.3.1.jar
jackcess-2.1.6.jar
Further, I have configured my data source in MSAccess-ds.xml and deployed in deploy folder. And i have kept my uber jar named "Service-MSAccessDB.jar" inside server lib folder as well as Ear/lib. Now, on server startup i get above error.
Now, if i rename my jar to "EService-MSAccessDB.jar", The error goes away.
The issue I feel is that JBoss server lib already contains hsqldb.jar. And when i place my uber jar, it causes some conflict. On startup, it tries to find a method i.e. DatabaseURL.parseURL(Ljava/lang/String;ZZ)Lorg/hsqldb/persist/HsqlProperties; which is present in my uber jar but not in hsqldb.jar. And when i rename my uber jar such that it is alphabetically higher in order with respect to hsqldb.jar, issue goes away.
Now, my question is, why is it looking for such a method while configuring DefaultDS which is default configuration of JBoss. How to resolve this issue without renaming my Uber jar as appending "E" in front of my Jar name does not make sense.
This JBoss server contains a copy of hsqldb.jar version 1.8.0.x for its internal use. You can replace it with a copy of hsqldb-2.3.1.jar (renamed to the name of the original jar) to avoid the conflict.

JBoss7 and Beans - required jars appear not to be used

We are trying to create a functional example with Hibernate, JBoss7, Beans and Servlets using Eclipse as an IDE.
In other example project we were able to make functional Servlets, and we were able to use Hibernate.
We created two eclipse projects:
A Dynamic web project, an Enterprise Java Beans (EJB) project and a EAR project connecting both.
Running a simple test.java file which uses hibernate (and worked on other projects), we the get errors:
Initial SessionFactory creation failed.org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
Exception in thread "main" java.lang.ExceptionInInitializerError
at exercicio.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:20)
at exercicio.DataBaseInterface.<init>(DataBaseInterface.java:17)
at exercicio.Test.main(Test.java:9)
Caused by: org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:156)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:303)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at exercicio.SessionFactoryUtil.configureSessionFactory(SessionFactoryUtil.java:32)
at exercicio.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:17)
... 2 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.validator.util.LoggerFactory.make(LoggerFactory.java:29)
at org.hibernate.validator.util.Version.<clinit>(Version.java:24)
at org.hibernate.validator.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:59)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:445)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:96)
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 org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 19 more
The problem now seems to be around the jars that we included using project Properties > Java Build Path > Add External Jars for the EJB project:
We added the slf4j-jdk14-1.7.5.jar and hibernate jars but the exception log appears to be indicating that we are still missing some jar.
If we remove the jars from the Java Build Path, the exception log is the same. So we think that the jars are not being deployed correctly, or some extra configuration is required... even thought they appear in the /lib folder inside the EJB project deployment folder.
Is there any procedure we are missing, or any probable causes to investigate? I'll add more info if needed. Thanks.
When using JBoss7 not all Jars are available to the application by default (for example slf4j). You have to specify which modules should be included in the classpath of the application by putting this information into a file in your application.
I always do it by adding jboss-deployment-structure.xml into my application (the EAR in your case).
Here's how https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7.
(The name of the module in your case would be org.slf4j)
Throwing slf4j jar in the libs folder can create a conflict with the slf4j module already included in JB7 by default... you have to add the dependency to your jboss-deployment-structure.xml
But if your hibernate jars are in the libs folder, they could fail resolve the dependency as well too... the way to go in JB7 would be to make a module for Hibernate too, the Nightie builds of JB7 already include an hibernate module, you could just copy the module from there, then add it to your jboss-deployment-structure.xml

Problem running a GWT 2.4 App on Tomcat

I have a problem running my gwt2.4rc1 application in a tomcat. The problem occurs when I try to make a requestfactory call. Then I get the exception at the bottom.
When I run GWT in development mode everything works fine. The gwt-dev. jar is in the lib folder of my webapp. I am using maven for dependency management. Could there be a problem with my configuration? I already had the error with gwt2.4 beta. If there are any other information required to solve this problem I am glad to provide them.
Regards,
Arne
SEVERE: Unexpected error
com.google.web.bindery.requestfactory.server.UnexpectedException: Unexpected checked exception
at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.die(ServiceLayerDecorator.java:216)
at com.google.web.bindery.requestfactory.server.ServiceLayerCache.getOrCache(ServiceLayerCache.java:242)
at com.google.web.bindery.requestfactory.server.ServiceLayerCache.resolveRequestFactory(ServiceLayerCache.java:198)
at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:201)
at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:125)
at com.google.web.bindery.requestfactory.server.RequestFactoryServlet.doPost(RequestFactoryServlet.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:261)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:175)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:162)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:203)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.NoClassDefFoundError: com/google/gwt/dev/util/StringKey
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2804)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1144)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1639)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1517)
at com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.validateProxy(RequestFactoryInterfaceValidator.java:1594)
at com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.validateEntityProxy(RequestFactoryInterfaceValidator.java:828)
at com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.maybeCheckProxyType(RequestFactoryInterfaceValidator.java:1540)
at com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.getDomainType(RequestFactoryInterfaceValidator.java:1374)
at com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.createDomainMethod(RequestFactoryInterfaceValidator.java:1192)
at com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.checkClientMethodInDomain(RequestFactoryInterfaceValidator.java:1079)
at com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.validateRequestContext(RequestFactoryInterfaceValidator.java:909)
at com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.validateRequestFactory(RequestFactoryInterfaceValidator.java:964)
at com.google.web.bindery.requestfactory.server.ResolverServiceLayer.resolveRequestFactory(ResolverServiceLayer.java:187)
at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.resolveRequestFactory(ServiceLayerDecorator.java:172)
at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.resolveRequestFactory(ServiceLayerDecorator.java:172)
at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.resolveRequestFactory(ServiceLayerDecorator.java:172)
at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.resolveRequestFactory(ServiceLayerDecorator.java:172)
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:616)
at com.google.web.bindery.requestfactory.server.ServiceLayerCache.getOrCache(ServiceLayerCache.java:233)
... 32 more
Caused by: java.lang.ClassNotFoundException: com.google.gwt.dev.util.StringKey
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1672)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1517)
... 57 more
There's a fix for this on its way over from RC to trunk. In the mean time, remove gwt-servlet from your dependencies and use requestfactory-servlet.jar instead.
I've always understood gwt-dev.jar to be the compiler and other development tools. If you believe that, there should be no dependency on it from your own code, and there is no reason for it to be in the WEB-INF/lib folder of your war file.
I see from this question that at least one other contributer to SO feels the same way, but the belief doesn't appear to be universal.
I'll update this answer if I can find anything one way or the other in the GWT docs.
Update:
The closest thing I could find was Organize Projects which shows gwt-dev as a referenced library not present in WEB-INF/lib. I can't find anything official that says either that you can or can't deploy it to your web server. In an old book GWT In Action (Hanson, 2007), page 551 says
You should never deploy the gwt-user.jar and gwt-dev.jar files to your server,
because they will interfere with your server; these JAR files contain their own
Tomcat server code, which is used when you're testing in hosted mode.
This is clearly out of date, since hosted mode isn't called that anymore and uses an embedded Jetty server rather than Tomcat, but that's the basis for my belief.
Ok I made it working :)
I used the gwt version compiled from here:
http://code.google.com/p/google-web-toolkit/source/browse/#svn%2Freleases%2F2.4
I did put gwt-servlet.jar and requestfactory-servlet.jar as dependencies in my project. The problem in the other thread occured because I used my own group-id for the compiled jars, so these were not used by gin and the gwt-maven-plugin. No everything works fine :)
Thanks for the help though!!

Java advanced imaging not available to EJB modules in Glassfish on Mac, but show up in EARs

I'm developing an application that uses the Geotools, which in turn uses the Java Advanced imaging (JAI) API to run under Glassfish. When I run my application from Netbeans as an EJB jar file it fails to deploy because of a ClassNotFoundException during CDI scanning :
com.google.common.collect.ComputationException: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading class org.autogena.skyserver.data.filetypes.SwathFile
at com.google.common.collect.ComputingConcurrentHashMap.compute(ComputingConcurrentHashMap.java:218)
....
Caused by: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading class org.autogena.skyserver.data.filetypes.SwathFile
at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:189)
.....
Caused by: java.lang.NoClassDefFoundError: javax/media/jai/PropertySource
at java.lang.ClassLoader.defineClass1(Native Method)
....
Caused by: java.lang.ClassNotFoundException: javax.media.jai.PropertySource
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
However, if I package the EJB module into an EAR file then I don't get the exception above and it seems to load ok.
Since on the Mac the JAI core classes are in the system extension library I'm baffled how it's not showing up on the classpath.
Is there a difference between an EJB jar and and EAR file when it comes to class loading, or is this a big in Glassfish / Weld?
Come to think of it - how is glassfish finding the libraries my prject uses anyway - they don't seem to be packaged into the ejb jar file - is netbeans doing something clever under the hood here that's going somehow askew?
thanks,
Josh
Try to configure the CLASSPATH on Glassfish in order to use the JAI libraries.

eclipselink PersistenceUnitLoadingEception in executable JAR

I am developing a stand-alone java application which uses eclipselink. It is all fine when I execute the app from eclipse IDE. But I've exported an executable JAR file, and since than I can not make eclipseLink work.
I have found similar issue in the Eclipse community forum here, but yet not too handy:
Please help,
My exception is the following:
01 dec. 2010 22:47:31,199 INFO Configuration:97 - Iniciate database
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:56)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.2.v
20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExcept
ion
Exception Description: An exception was thrown while searching for persistence a
rchives with ClassLoader: java.net.URLClassLoader#61de33
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services
- 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoad
ingExceptionException Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../
Internal Exception: java.net.MalformedURLException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.ex
ceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126
)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:133)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:65)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:33)
at eu.agilelabs.pillAgent.db.dam.DataManagerImplJPA.(DataManagerIm
plJPA.java:36)
at eu.agilelabs.pillAgent.db.dam.DataManagerImplJPA.getInstance(DataMana
gerImplJPA.java:47)
at eu.agilelabs.configuration.Configuration.(Configuration.java:98
)
at eu.agilelabs.configuration.Configuration.getInstance(Configuration.ja
va:119)
at eu.agilelabs.pillAgent.core.Main.main(Main.java:15)
... 5 more
Caused by: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.0.2.v
20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExcept
ion
Exception Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../
Internal Exception: java.net.MalformedURLException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.ex
ceptionProcessingPersistenceXML(PersistenceUnitLoadingException.java:117)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceXML(PersistenceUnitProcessor.java:444)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceArchive(PersistenceUnitProcessor.java:401)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.getPersistenceUnits(PersistenceUnitProcessor.java:310)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfoInArchive(JPAInitializer.java:149)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfoInArchives(JPAInitializer.java:136)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfo(JPAInitializer.java:125)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:98)
... 13 more
Caused by: java.net.MalformedURLException
at java.net.URL.(Unknown Source)
at java.net.URL.(Unknown Source)
at java.net.URL.(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrent
Entity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineD
ocVersion(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
nknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
nknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown So
urce)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Un
known Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.p
arse(Unknown Source)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceXML(PersistenceUnitProcessor.java:442)
... 19 more
I think this line must be the key:
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services
- 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoad
ingExceptionException Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../
I have managed to solve it. I changed the way eclipse exports the jar file. If it extracts required libraries into the jar everything works great. Thank you anyway!
Some background info
As the link you've provided says, EclipseLink doesn't seem to support loading persistence.xml when the EclipseLink jar is embedded in your app's jar.
As I understand it, standard non-customized Java doesn't support runnable jars that load classes from embedded jars. The runnable jar that Eclipse creates is able to overcome that limitation by adding a custom classloader (org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader) to your app's jar. The custom classloader apparently is where EclipseLink runs into this issue.
With that said, in Eclipse Helios, I've found it more manageable to "Copy required libraries into a sub-folder next to the generated JAR" rather than to "Extract required libraries into generated JAR."
Choosing the copy option keeps the eclipselink jar intact, as opposed to Eclipse extracting the various .class files and cluttering your application's jar. True, your app will no longer be distributable as a single jar, but from a manageability standpoint, this seems better than the extract-libraries option.
I found the respective solution (that is if you are not using EclipseLink 2.3.2), as mentioned by GaDo in Bug 364748, the solution is to add the following line into MANIFEST.MF
Eclipse-BundleShape: dir
This leads to the plug-in being exported as directory instead as JAR file, which makes persistence.xml accessible.
I was using EclipseLink 2.3.2, with Eclipse Indigo, and was still getting the error.
Then, like a fool, I realized that I was choosing "Package required libraries into generated JAR" instead of "Extract required libraries into generated JAR" works.
Not sure what the difference is, although I've noticed that some of my JARs only work when I create when using "Package required...", and others only work when I create them using "Extract required...".
Not sure why that is. Ultimately, I don't really care, as long as the resulting JAR has no external dependencies.
BTW, the other option that was proposed (modifying the JAR's manifest file) didn't work for me. I extracted the manifext (jar xf MYJAR.jar META-INF/MANIFEST.MF), added Eclipse-BundleShape: dir, injected it into the jar (jar umf META-INF/MANIFEST.MF MYJAR.jar), and verified that the manifest changed. Same error.
Right click on the project -> Properties -> Java Build Path -> Order and Export, and select the libraries
Right click on the project -> Export... -> Runnable JAR file -> Copy required libraries into a sub-folder next to the generated JAR
This worked for me.
This issue has been fixed in EclipseLink 2.3.2
I upgraded and it went away