-
Re: Strange XML compiler error - Correction
Below I stated that this is a compiler error. It is not. It actually occurs
when I run the code after compiling successfully.
David Rancour
"David Rancour" <david_rancour@hotmail.com> wrote:
>
>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
-
Re: Strange XML compiler error - Correction
When you run a Java application and you get a NoClassDefFoundError, it means
the class it can't find isn't in your classpath.
PC2
"David Rancour" <david_rancour@hotmail.com> wrote in message
news:3b26177f$1@news.devx.com...
>
> Below I stated that this is a compiler error. It is not. It actually
occurs
> when I run the code after compiling successfully.
>
> David Rancour
>
> "David Rancour" <david_rancour@hotmail.com> wrote:
> >
> >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
> > {
> > file://InputStream in = s.getInputStream();
> > file://bytesAvailable = in.available();
> > file://byte[] clientrequest = new byte[bytesAvailable];
> > file://s.getInputStream().read(clientrequest);
> > file://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());
> > file://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
>
-
Re: Strange XML compiler error - Correction
Paul,
I am importing the import org.xml.sax.*; package which contains SAXException
class also I am importing the javax.xml.parsers.*; package which contains
the ParserConfigurationException class. The fact that the compiler compiles
this code without error tells me that these packages are in fact being resolved
correctly. For the record, CLASSPATH is as follows:
CLASSPATH=.;c:\jdk13\bin;c:\jakarta-tomcat-4.0-b5\common\lib\servlet.jar;C:\jsdk2.1;C:\jdk13\jre\lib\ext;
And the .jar's live in the C:\jdk13\jre\lib\ext directory
Any other idea's??
"Paul Clapham" <pclapham@core-mark.com> wrote:
>When you run a Java application and you get a NoClassDefFoundError, it means
>the class it can't find isn't in your classpath.
>
>PC2
>
>"David Rancour" <david_rancour@hotmail.com> wrote in message
>news:3b26177f$1@news.devx.com...
>>
>> Below I stated that this is a compiler error. It is not. It actually
>occurs
>> when I run the code after compiling successfully.
>>
>> David Rancour
>>
>> "David Rancour" <david_rancour@hotmail.com> wrote:
>> >
>> >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
>> > {
>> > file://InputStream in = s.getInputStream();
>> > file://bytesAvailable = in.available();
>> > file://byte[] clientrequest = new byte[bytesAvailable];
>> > file://s.getInputStream().read(clientrequest);
>> > file://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());
>> > file://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
>>
>
>
-
Re: Strange XML compiler error - Correction
As I thought, you are running this in a servlet. The classpath of a servlet
is generally NOT the environment value CLASSPATH, but some other value
that's configured in your servlet engine (which appears to be Tomcat in your
case).
PC2
"David Rancour" <david_rancour@hotmail.com> wrote in message
news:3b2636e1$1@news.devx.com...
>
> Paul,
>
> I am importing the import org.xml.sax.*; package which contains
SAXException
> class also I am importing the javax.xml.parsers.*; package which contains
> the ParserConfigurationException class. The fact that the compiler
compiles
> this code without error tells me that these packages are in fact being
resolved
> correctly. For the record, CLASSPATH is as follows:
>
>
CLASSPATH=.;c:\jdk13\bin;c:\jakarta-tomcat-4.0-b5\common\lib\servlet.jar;C:\
jsdk2.1;C:\jdk13\jre\lib\ext;
>
> And the .jar's live in the C:\jdk13\jre\lib\ext directory
>
> Any other idea's??
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks