Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Java 1.5 and Leopard problem

Upgraded to Leopard and now with an Eclipse project that uses JUnit tests, I get SAX parsing errors that may revolve around JAXB or jaxp.jar issues. Everything worked under Tiger, and I am NOT interested in the 1.6 issue, just trying to use 1.5.

Thanks in advance for any hints or workarounds.

G5 dual 2.5, Mac OS X (10.5), 6 gb RAM

Posted on Nov 5, 2007 3:40 PM

Reply
7 replies

Nov 23, 2007 11:44 AM in response to jchodakowski

I use Hibernate to handle database accesses, and the utility class HibernateUtil is crucial to this. When I run my application using Clover to measure coverage, I get the coverage report shown below. Notice the places where there is a 1 or 4 - these indicate the lines were executed when I ran the application. Particularly, a session factory is returned 4 times in this routine. Now skip to below this first report.


50 */
51 public class HibernateUtil {
52
53 private static Log log = LogFactory.getLog(HibernateUtil.class);
54 private static final String INTERCEPTOR_CLASS = "hibernate.util.interceptor_class";
55 private static Configuration configuration;
56 private static SessionFactory sessionFactory;
57 static {
58 // Create the initial SessionFactory from the default configuration
59 // files
60 1 try {
61 // Replace with Configuration() if you don't use annotations or JDK
62 // 5.0
63 1 configuration = new AnnotationConfiguration();
64 // This custom entity resolver supports entity placeholders in XML
65 // mapping files
66 // and tries to resolve them on the classpath as a resource
67 1 configuration
68 .setEntityResolver(new ImportFromClasspathEntityResolver());
69 // Read not only hibernate.properties, but also hibernate.cfg.xml
70 // If GlucosePlugin is null, then am doing unit tests
71 1 if (GlucosePlugin.getDefault() == null) {
72 0 log.info("Null glucose plugin as expected during unit tests");
73 0 configuration.configure("/hibernate.hsqldb.xml");
74 } else {
75 1 if (GlucosePlugin.getDefault().getDatabasePreference() == "hsqldb") {
76 1 log.info("HSQLDB database configuration occuring");
77 1 configuration.configure("/hibernate.hsqldb.xml");
78 } else {
79 0 if (GlucosePlugin.getDefault().getDatabasePreference() == "mysql") {
80 0 configuration.configure("/hibernate.mysql.xml");
81 } else {
82 // Use hibernate.cfg.xml which could be for any database
83 0 log.info("Fell through to default configuration");
84 0 configuration.configure();
85 }
86 }
87 }
88 // configuration.configure();
89 // Set global interceptor from configuration
90 1 setInterceptor(configuration, null);
91 1 if (configuration.getProperty(Environment.SESSION FACTORYNAME) != null) {
92 // Let Hibernate bind the factory to JNDI
93 0 configuration.buildSessionFactory();
94 } else {
95 // or use static variable handling
96 1 sessionFactory = configuration.buildSessionFactory();
97 }
98 } catch (Throwable ex) {
99 // We have to catch Throwable, otherwise we will miss
100 // NoClassDefFoundError and other subclasses of Error
101 0 log.error("Building SessionFactory failed.", ex);
102 0 throw new ExceptionInInitializerError(ex);
103 }
104 }
105
106 /**
107 * Returns the original Hibernate configuration.
108 *
109 * @return Configuration
110 */
111 1 public static Configuration getConfiguration() {
112 1 return configuration;
113 }
114
115 /**
116 * Returns the global SessionFactory.
117 *
118 * @return SessionFactory
119 */
120 4 public static SessionFactory getSessionFactory() {
121 4 SessionFactory sf = null;
122 4 String sfName = configuration
123 .getProperty(Environment.SESSION FACTORYNAME);
124 4 if (sfName != null) {
125 0 log.debug("Looking up SessionFactory in JNDI.");
126 0 try {
127 0 sf = (SessionFactory) new InitialContext().lookup(sfName);
128 } catch (NamingException ex) {
129 0 throw new RuntimeException(ex);
130 }
131 } else {
132 4 sf = sessionFactory;
133 }
134 4 if (sf == null)
135 0 throw new IllegalStateException("SessionFactory not available.");
136 4 return sf;
137 }

This is a small fraction of the error trace. Notice that my loggins statements indicate that line 72 of HibernateUtil is hit - since I am doing this from unit tests, there is no glucose plugin. But it does find the configuration file, and then fails. Below the trace is my clover coverage report.

12:35:34,768 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
12:35:35,448 INFO HibernateUtil:72 - Null glucose plugin as expected during unit tests
12:35:35,451 INFO Configuration:1426 - configuring from resource: /hibernate.hsqldb.xml
12:35:35,451 INFO Configuration:1403 - Configuration resource: /hibernate.hsqldb.xml
Warning: Caught exception attempting to use SAX to load a SAX XMLReader
Warning: Exception was: java.lang.ClassNotFoundException: org/apache/xerces/parsers/SAXParser
Warning: I will print the stack trace then carry on using the default SAX parser
java.lang.ClassNotFoundException: org/apache/xerces/parsers/SAXParser
at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:189)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:150)
at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
at org.dom4j.io.SAXReader.read(SAXReader.java:435)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)

NOW below is the clover coverage report for the unit tests and you can see that the code gets to line 73 where it tries to configure from the xml file. This fails, yielding me the SAX error above.

59 // files
60 1 try {
61 // Replace with Configuration() if you don't use annotations or JDK
62 // 5.0
63 1 configuration = new AnnotationConfiguration();
64 // This custom entity resolver supports entity placeholders in XML
65 // mapping files
66 // and tries to resolve them on the classpath as a resource
67 1 configuration
68 .setEntityResolver(new ImportFromClasspathEntityResolver());
69 // Read not only hibernate.properties, but also hibernate.cfg.xml
70 // If GlucosePlugin is null, then am doing unit tests
71 1 if (GlucosePlugin.getDefault() == null) {
72 1 log.info("Null glucose plugin as expected during unit tests");
73 1 configuration.configure("/hibernate.hsqldb.xml");
74 } else {
75 0 if (GlucosePlugin.getDefault().getDatabasePreference() == "hsqldb") {
76 0 log.info("HSQLDB database configuration occuring");
77 0 configuration.configure("/hibernate.hsqldb.xml");
78 } else {
79 0 if (GlucosePlugin.getDefault().getDatabasePreference() == "mysql") {
80 0 configuration.configure("/hibernate.mysql.xml");
81 } else {
82 // Use hibernate.cfg.xml which could be for any database
83 0 log.info("Fell through to default configuration");
84 0 configuration.configure();
85 }
86 }
87 }
88 // configuration.configure();
89 // Set global interceptor from configuration
90 0 setInterceptor(configuration, null);
91 0 if (configuration.getProperty(Environment.SESSION FACTORYNAME) != null) {
92 // Let Hibernate bind the factory to JNDI
93 0 configuration.buildSessionFactory();
94 } else {
95 // or use static variable handling
96 0 sessionFactory = configuration.buildSessionFactory();
97 }
98 } catch (Throwable ex) {
99 // We have to catch Throwable, otherwise we will miss
100 // NoClassDefFoundError and other subclasses of Error
101 1 log.error("Building SessionFactory failed.", ex);
102 1 throw new ExceptionInInitializerError(ex);
103


Sorry for the length of this message, but I appreciate any help that anyone can provide. This has been a difficult problem to figure out.

- Mike

Dec 11, 2007 11:11 AM in response to J. Michael Dean

I'm seeing a similar trace in an app I work on (same last couple lines). A google search turned up this thread, so before trying to troubleshoot it on my own I thought I'd start by asking whether or not you resolved the problem (and if so how)?

I'm using eclipse on OS X 10.5.1 with Java 1.5. I'm not confident that it broke when I upgraded to 10.5.x and can't easily test on another mac. However, it still works on windows and linux, so I think it's unlikely to be something that changed in the code base.



Warning: Caught exception attempting to use SAX to load a SAX XMLReader Warning: Exception was:
java.lang.ClassNotFoundException:
org/apache/xerces/parsers/SAXParser
Warning: I will print the stack trace then carry on using the default SAX parser java.lang.ClassNotFoundException: org/apache/xerces/parsers/SAXParser
at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:189)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:150)
at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:74)
at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:647)
at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:530)
at org.dom4j.io.SAXReader.read(SAXReader.java:309)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:287)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:355)
at com.quintron.vx.core.hibernate.VXHBUtils.buildConfiguration(VXHBUtils.java:158)
at com.quintron.vx.core.hibernate.VXHBUtils.buildConfiguration(VXHBUtils.java:122)
at com.quintron.vx.core.hibernate.VXHBUtils.buildConfiguration(VXHBUtils.java:135)
at com.quintron.vx.core.hibernate.VXHBUtils.buildConfiguration(VXHBUtils.java:131)

Jan 6, 2008 12:58 PM in response to ctl271

I continue to have problems with JUnit and classpath in Eclipse. The error that I get on my machine is the same as your error, and I resolve this by adding Xerxes to the classpath of the JUnit run configuration. I never had to do this with Tiger.

My real problem is when using another library, Drools, I cannot get the JUnit classpath to resolve correctly. My own code, when exported as RCP from Eclipse, runs fine, but I cannot run unit tests for Drools.

I am interested that there was a solution involving ant, but I went back and made sure my ant distribution was already the Eclipse contained apache ant. Had no effect on the errors. I also removed the ant installation I already had on my machine in the usr/bin location, and still no effect.

Any assistance will be greatly appreciated.

Java 1.5 and Leopard problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.