• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

javax xml parsers FactoryConfigurationError

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
i am getting the following error while running my program.
program:-


import java.io.*;

import org.xml.sax.*;
import org.apache.crimson.jaxp.SAXParserFactoryImpl;


import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

public class BooksLibrary extends HandlerBase
{
protected static final String XML_FILE_NAME = "C:\\Shanker\\xmlfiles\\saxprog\\library1.xml";

public static void main (String argv [])
{
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter (System.out, "UTF8");

// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(XML_FILE_NAME), new BooksLibrary() );

} catch (Throwable t) {
t.printStackTrace ();
}
System.exit (0);
}

static private Writer out;

//===========================================================
// Methods in SAX DocumentHandler
//===========================================================

public void startDocument ()
throws SAXException
{
showData ("<?xml version='1.0' encoding='UTF-8'?>");
newLine();
}

public void endDocument ()
throws SAXException
{
try {
newLine();
out.flush ();
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}

public void startElement (String name, AttributeList attrs)
throws SAXException
{
showData ("<"+name);
if (attrs != null) {
for (int i = 0; i < attrs.getLength (); i++) {
showData (" ");
showData (attrs.getName(i)+"=\""+attrs.getValue (i)+"\"");
}
}
showData (">");
}

public void endElement (String name)
throws SAXException
{
showData ("</"+name+">");
}

public void characters (char buf [], int offset, int len)
throws SAXException
{
String s = new String(buf, offset, len);
showData (s);
}

//===========================================================
// Helpers Methods
//===========================================================

// Wrap I/O exceptions in SAX exceptions, to
// suit handler signature requirements
private void showData (String s)
throws SAXException
{
try {
out.write (s);
out.flush ();
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}

// Start a new line
private void newLine ()
throws SAXException
{
String lineEnd = System.getProperty("line.separator");
try {
out.write (lineEnd);
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}
}


Error:
C:\shanker\xmlfiles>java -Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParse
r BooksLibrary
Exception in thread "main" javax.xml.parsers.FactoryConfigurationError: java.lan
g.ClassNotFoundException: org.apache.crimson.jaxp.SAXParserFactoryImpl
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:
120)
at BooksLibrary.main(BooksLibrary.java:18)
[ November 06, 2004: Message edited by: sai Narayan ]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the CLASSPATH again, like in your other example.
Let us know if that doesn't work.

- m
 
sai Narayan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi madhav,
I have set all the classpath as per ur guidance.even then my program is giving error .can you please help.
program:-
/*com and org folders are sitting in the folder where my program is residing and i have also set the currrent folder in my classpath*/

import java.io.*;

import org.xml.sax.*;
import org.apache.crimson.jaxp.*;
import com.macromedia.crimson.jaxp.*;

import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

public class BooksLibrary extends HandlerBase
{
protected static final String XML_FILE_NAME = "C:\\Shanker\\xmlfiles\\saxprog\\library1.xml";

public static void main (String argv [])
{
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter (System.out, "UTF8");

// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(XML_FILE_NAME), new BooksLibrary() );

} catch (Throwable t) {
t.printStackTrace ();
}
System.exit (0);
}

static private Writer out;

//===========================================================
// Methods in SAX DocumentHandler
//===========================================================

public void startDocument ()
throws SAXException
{
showData ("<?xml version='1.0' encoding='UTF-8'?>");
newLine();
}

public void endDocument ()
throws SAXException
{
try {
newLine();
out.flush ();
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}

public void startElement (String name, AttributeList attrs)
throws SAXException
{
showData ("<"+name);
if (attrs != null) {
for (int i = 0; i < attrs.getLength (); i++) {
showData (" ");
showData (attrs.getName(i)+"=\""+attrs.getValue (i)+"\"");
}
}
showData (">");
}

public void endElement (String name)
throws SAXException
{
showData ("</"+name+">");
}

public void characters (char buf [], int offset, int len)
throws SAXException
{
String s = new String(buf, offset, len);
showData (s);
}

//===========================================================
// Helpers Methods
//===========================================================

// Wrap I/O exceptions in SAX exceptions, to
// suit handler signature requirements
private void showData (String s)
throws SAXException
{
try {
out.write (s);
out.flush ();
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}

// Start a new line
private void newLine ()
throws SAXException
{
String lineEnd = System.getProperty("line.separator");
try {
out.write (lineEnd);
} catch (IOException e) {
throw new SAXException ("I/O error", e);
}
}
}


Error:-
C:\shanker\xmlfiles\saxprog>java BooksLibrary
Exception in thread "main" java.lang.NoClassDefFoundError: org/xml/sax/SAXNo
ognizedException
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:237)
at javax.xml.parsers.FactoryFinder.newInstance(Unknown Source)
at javax.xml.parsers.FactoryFinder.find(Unknown Source)
at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source)
at BooksLibrary.main(BooksLibrary.java:20)
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi madhav,
I have set all the classpath as per ur guidance.even then my program is giving error .can you please help.
program:-
/*com and org folders are sitting in the folder where my program is residing and i have also set the currrent folder in my classpath*/



com and org folders.......

In the other thread you seem to indicate that you are using JSDK1.4.
Now you are mentioning com and org folders, are you trying to build
everything ?

Generally, you don't need the com and org folders. You use the jars that
you get from the JSDK directly. That's what I was expecting you to do.
If you could explain what you are trying to do we could figure out a
solution.
Regds.

- m

ps: I will close the other thread, lets continue the discussion here.
 
sai Narayan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhav,
Actually i am trying to run the above program.so as per our discussion i have added JAVA_HOME\lib in my classpath.even then i an getting the following error.can you please help me out.I have really got tired of seeing this error.
error:-
C:\shanker\xmlfiles\saxprog>java BooksLibrary
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/crimson/ja
xp/SAXParserFactoryImpl (wrong name: com/macromedia/crimson/jaxp/SAXParserFactor
yImpl)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:493)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:11
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:
117)
at BooksLibrary.main(BooksLibrary.java:20)
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i am trying to run the above program.so as per our discussion i have added JAVA_HOME\lib in my classpath.even then i an getting the following error.can you please help me out.I have really got tired of seeing this error.


Echo the CLASSPATH / JAVA_HOME and post it here.
On Windows, at the command prompt do a

>set CLASSPATH
>set JAVA_HOME

Or on UNIX do

%echo %CLASSPATH%
%echo %JAVA_HOME%

Let us know what it is.

- m
 
sai Narayan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhav,
here is my classpath and JAVA_HOME:-
C:\>echo %classpath%
C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar;C:\shanker\java\jarfiles\j2ee
.jar;C:\shanker\java\javaprograms12\classes12.jar;C:\Tomcat 5.0\webapps\chapter01\WEB-INF\lib\classes12.jar;C:\shanker\java\jarfiles;C:\WebSphere\AppServer\bin;
C:\shanker\junit3.8.1\junit.jar;C:\shanker\Xerces-J-bin.2.6.2\xerces-2_6_2\Xerce
sSamples.jar;C:\shanker\xmlfiles\jaxp.jar;C:\shanker\xmlfiles\parser.jar;C:\shan
ker\xmlfiles\xalan.jar;C:\shanker\xmlfiles\saxprog;C:\j2sdk1.4.2_04\lib;C:\j2sdk
1.4.2_04\lib\org\apache\crimson\jaxp

C:\>echo %JAVA_HOME%
C:\j2sdk1.4.2_04\lib
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!