简体   繁体   中英

NoClassDefFoundError in org.apache.openjpa.lib.xml.XMLFactory from inside Karaf

We are trying a simple use case of reading/writing to a mysql database using JPA from Camel routes inside Karaf. This frequently/always causes the following stacktrace when camel is loading my code that contains routes:

2013-07-19 17:01:47,178 | WARN | ft.WorkoutEntity | JpaConsumer | rg.apache.camel.util.CamelLogger 224 | 68 - org.apache.camel.camel-core - 2.10.4 | Consumer Consumer[jpa://WorkoutEntity] failed polling endpoint: Endpoint[jpa://WorkoutEntity]. Will try again at next poll. Caused by: [java.lang.NoClassDefFoundError - Could not initialize class org.apache.openjpa.lib.xml.XMLFactory] java.lang.NoClassDefFoundError: Could not initialize class org.apache.openjpa.lib.xml.XMLFactory at org.apache.openjpa.jdbc.sql.SQLErrorCodeReader.parse(SQLErrorCodeReader.java:107) at org.apache.openjpa.jdbc.sql.DBDictionary.endConfiguration(DBDictionary.java:4712) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443) at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:199) at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:100)

XMLFactory is contained in an OpenJPA-aggregate bundle that my bundle has imported. I can even instantiate other objects from the same org.apache.openjpa.lib.xml package.

I cracked open the opensource OpenJPA code and took a look at XMLFactory. There is a static block at the top that should be called when the class is loaded. The static block does not look to be doing anything complex, just instantiating SAX and DOM parser factories.

If, in my java code that contains routes, I add the following line:

org.apache.openjpa.lib.xml.XMLFactory.getClass()

to get the class loaded in the ClassLoader, the error sometimes will stop.

Here's some version info:

Karaf => 2.3.2

Camel => Tried 2.10.4 and 2.11.1

OpenJPA => Tried 2.2.0 and 2.2.2

Mysql => 5.1.25

Let me know if you need more info.

-New Info- I turned on DEBUG level logging from karaf prompt and now see this error before the NoClassDefError

2013-07-19 17:35:36,784 | DEBUG | ft.WorkoutEntity | TransactionTemplate | tion.support.TransactionTemplate 160 | 75 - org.springframework.transaction - 3.2.3.RELEASE | Initiating transaction rollback on application exception javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:122)[:2.2.0] at org.apache.openjpa.lib.xml.XMLFactory.(XMLFactory.java:60) at org.apache.openjpa.jdbc.sql.SQLErrorCodeReader.parse(SQLErrorCodeReader.java:107) at org.apache.openjpa.jdbc.sql.DBDictionary.endConfiguration(DBDictionary.java:4712) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443) at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:199) at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:100) at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:603)

This explains the NoClassDefFound error.

You probably don't have xerces installed.

Try installing it and its dependencies from maven:

osgi:install wrap:mvn:xml-apis/xml-apis/1.4.01
osgi:install wrap:mvn:xml-resolver/xml-resolver/1.2
osgi:install wrap:mvn:xerces/xercesImpl/2.11.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM