Hi all, I am trying to write a Java Server that uses sockets to listen on
a port for incoming XML transaction so that it may process them. However
I am getting some strange compiler error. I want to use the SAX API as it
seems to be the lightest weight option and works just fine for what I need.
You must call SAXParserFactory.newInstance(); to get an SAXParserFactory
object so you can use to get a new parser instance. Once you have this object,
you then call the obj.newSAXParser() method to get a new instance of a parser.
This method call can throw 2 exceptions,a SAXException and a ParserConfigurationException
each of which must be caught. So I wrapped up the call in a try clause with
2 catch clauses, saved and comiled just fine. However when I try to run the
server I get 'Exception in thread "main" java.lang.NoClassDefFoundError:'
for whichever exception I catch last..!! So, if I catch the SAXException
first then the error I get says it can't find the class definition for javax/xml/parsers/ParserConfigurationException.
But, if I catch the SAXException last then I get org/xml/sax/SAXException
class not found.What is happening here? Here is the Java code for my server.
It compiles just fine:

import java.net.*;
import java.io.*;
import javax.xml.parsers.*;
import org.xml.sax.*;

public class ForumServer
{

ServerSocket primarySocket;

public ForumServer()
{
try
{
primarySocket = new ServerSocket(5775);
System.out.println("Initialization Complete");
}
catch (IOException e)
{
System.out.println(e);
System.exit(0);
}
waitForClients();
}

private void waitForClients()
{
while (true)
{
try
{
Socket clientsocket = primarySocket.accept();
System.out.println("Request Received");
processRequest(clientsocket);
System.out.println("Request Processed");
clientsocket.close();
System.out.println("Socket Closed");
System.exit(0);
}
catch (IOException e)
{
System.out.println(e);
System.exit(0);
}
}
}

private void processRequest(Socket s)

{
int bytesAvailable;

try
{
//InputStream in = s.getInputStream();
//bytesAvailable = in.available();
//byte[] clientrequest = new byte[bytesAvailable];
//s.getInputStream().read(clientrequest);
//String xmlRequest = new String(clientrequest);
javax.xml.parsers.SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(false);
try
{
javax.xml.parsers.SAXParser sp = spf.newSAXParser();
}
catch (ParserConfigurationException pex)
{
}
catch (SAXException se)
{
}
InputSource input = new InputSource(s.getInputStream());
//sp.parse(input,new xmlEventHandler());
}
catch (IOException e)
{
}
}

public static void main(String[] args)
{
ForumServer app = new ForumServer();
}
}

I have verified that both class files exist in the jar file and the fact
that the code compiles w/o error tells me that all the imports are there...
Anyone else notice this or have any advice?

Thanks!!

David Rancour