You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rpc-user@xml.apache.org by Frederik Uyttersprot <fr...@pandora.be> on 2002/04/22 18:40:25 UTC

java.lang.NoClassDefFoundError problem

Hello,

I just started playing with XML-RPC and have the following problem.
I'm also quite new to Java. I'm trying an example from Oreilly's Java
& XML 2nd edition, getting the following error,

D:\Java\bin\java.exe   test.server.HelloServer
Working Directory - D:\Java\temp\
Class Path - D:\Java\temp;d:\java\lib;d:\java\xmlrpc\xmlrpc-1.1.jar;.;d:\program
files\Kawa\kawaclasses.zip;D:\Java\lib\tools.jar;D:\Java\jre\lib\rt.jar;D:\Java\jre\lib\i18n.jar
java.lang.NoClassDefFoundError: test/server/HelloServer Exception in thread "main" Process Exit...

What can I do here? Compilation is error free...

Thanks in advance.

The code,

package test.server;

import java.io.IOException;

import org.apache.xmlrpc.*;
import test.handler.*;

public class HelloServer 
{
        public static void main() 
        {
                try 
                {
                        System.out.println("Setting up...");
                        
                        WebServer server = new WebServer(8080);
                        
                        server.addHandler("hello", new HelloHandler());
                        
                        server.run();
                        
                        System.out.println("Now accepting requests...");
                        
                } catch(IOException e) 
                {
                        System.out.println("Could not start server : " + e.getMessage());
                }
        }
}

package test.handler;

public class HelloHandler 
{
        public String sayHello(String name) 
        {
                return "Hello " + name;
        }
}

PATH IS == d:\java\lib;d:\java\xmlrpc;\java\xerces;.;d:\program
files\Kawa\kawaclasses.zip;D:\Java\lib\tools.jar;D:\Java\jre\lib\rt.jar;D:\Java\jre\lib\i18n.jar

Got this by using,

import java.util.*;

public class PrintClassPath
{
    public static void main(String args[])
    {
        try
        {
            System.out.println("PATH IS == " + System.getProperty("java.class.path"));
        } catch (Throwable t)
          {
            t.printStackTrace();
          }
    }
}


Error encountered: Unable to resolve target object: testsoap.TestWsImpl

Posted by Phoay Phoay Koay <pp...@ibridgecapital.com>.
Hi all, 
I 'm trying to develop a web service using SOAP with database connection. Three files areinvolved :
testsoap.TestWsImpl.java, testDD.xml, 
testsoap.client.TestClient.java

My Implementation calss is
package testsoap;

import java.io.*;
import java.lang.*;
import java.sql.*;
import java.util.*;

public class TestWsImpl
{
 
  public TestWsImpl() 
 { 
 }

 //******************************************************************//
 // callConnection 
 // TODO : To get connection
 //******************************************************************//
 public Connection callConnection()
 {
  Connection conn =null;
  try
  {
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
       conn = DriverManager.getConnection("jdbc:odbc:ws","ma","ma");
  }
  catch(Exception ex)
  {
  }
  return conn;
 }

 //******************************************************************//
 // Function:getBookTitle
 //******************************************************************//
  
 public String getBookTitle(String artist) 
 { 
  PreparedStatement stmt;
  ResultSet rs;
  String retValue="";
   String query ="";
  Connection conn = null;
  try
  {
     
   
   conn = callConnection();    
   query = "select bookTitle from dbo.pptest where bookArtist = ?";
   stmt = conn.prepareStatement(query);
   stmt.setString(1,artist);
   rs = stmt.executeQuery();
   
   while(rs.next())
   {
    retValue =rs.getString(1);
   }
   System.out.println("Book Title For " + artist + " : " + retValue);
   rs.close();
   stmt.close();
   conn.close();
   conn = null;
     
  }
  catch(Exception e1){
   if (conn!=null)
   System.out.println("getBookTitle() : Release Connection Failed! ");
   return null;
  }   
  return retValue;
} 
 
 
}

------------------------------------------------------------------------------------------------------------------------------
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
             id="urn:cd-test-ws"
>
  <isd:provider type="java"
                scope="Application"
                methods="getBookTitle"
  >
    <isd:java class="testsoap.TestWsImpl" static="false" />
  </isd:provider>

  <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
 
</isd:service>
-----------------------------------------------------------------------------------------------------------------------------

testsoap.client.TestClient.java
package testsoap.client;
 
/*
 Required due to use of URL class, required by Call Class
*/
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import testsoap.*; 


public class TestClient {
 
  public void getData(URL url, String artist) throws SOAPException {
    
 System.out.println("Listing current Books.");
    System.out.println("Book's Artist Name : " + artist);

    // Build the Call object
    Call call = new Call( );
    call.setTargetObjectURI("urn:cd-test-ws");
    call.setMethodName("getBookTitle");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
 
 // Set up parameters
    Vector params = new Vector( );
    params.addElement(new Parameter("artist", String.class, artist, null));
    call.setParams(params);

    // Invoke the call
    Response response;
 System.out.println("URL: " + url);
    response = call.invoke(url, "");

    if (!response.generatedFault( )) {
    System.out.println("3");
       Parameter returnValue = response.getReturnValue( );
       String title = (String)returnValue.getValue();
       System.out.println(" Client Test Result is (TITLE) : " + title);
    
    } else {
     System.out.println("4");
      Fault fault = response.getFault( );
      System.out.println("Error encountered: " + fault.getFaultString( ));
    }
  }
 
  public static void main(String[] args) {
    if (args.length != 2) {
      System.out.println("Usage: java testsoap.TestClient [SOAP server URL]");
      return;
    }
 
    try {
      // URL for SOAP server to connect to
      URL url = new URL(args[0]);
   String param = args[1];
  System.out.println(param);
      // List the current CDs
      TestClient cl = new TestClient( );
      cl.getData(url, param);

    } catch (Exception e) {
      e.printStackTrace( );
    }
  }
}

------------------------------------------------------------------------------------------------------


D:\soapDev\src>java -classpath d:\xerces-1_4_4\xerces.jar;d:\tomsoap\lib\mail.jar;d:\tomsoap\lib\activation.jar;d:\tomsoap\lib\soap.jar;D;\tomsoap\lib\poolman\jdbc2_0-stdext.jar;d:\tomsoap\lib\bsf.jar;d:\tomsoap\lib\db2java.zip;d:\tomsoap\lib\js.jar;D:\soapDev\src;. testsoap.client.TestClient http://localhost:8080/soap/servlet/rpcrouter "John"

Result : 
John
Listing current Books.
Book's Artist Name : John
URL: http://localhost:8080/soap/servlet/rpcrouter

Error encountered: Unable to resolve target object: testsoap.TestWsImpl

Can anybody tell me that what is happening to the classpath that i set? What is the solution for this case?
Thanks in advance.


Regards
PP





Error encountered: Unable to resolve target object: testsoap.TestWsImpl

Posted by Phoay Phoay Koay <pp...@ibridgecapital.com>.
Hi all, 
I 'm trying to develop a web service using SOAP with database connection. Three files areinvolved :
testsoap.TestWsImpl.java, testDD.xml, 
testsoap.client.TestClient.java

My Implementation calss is
package testsoap;

import java.io.*;
import java.lang.*;
import java.sql.*;
import java.util.*;

public class TestWsImpl
{
 
  public TestWsImpl() 
 { 
 }

 //******************************************************************//
 // callConnection 
 // TODO : To get connection
 //******************************************************************//
 public Connection callConnection()
 {
  Connection conn =null;
  try
  {
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
       conn = DriverManager.getConnection("jdbc:odbc:ws","ma","ma");
  }
  catch(Exception ex)
  {
  }
  return conn;
 }

 //******************************************************************//
 // Function:getBookTitle
 //******************************************************************//
  
 public String getBookTitle(String artist) 
 { 
  PreparedStatement stmt;
  ResultSet rs;
  String retValue="";
   String query ="";
  Connection conn = null;
  try
  {
     
   
   conn = callConnection();    
   query = "select bookTitle from dbo.pptest where bookArtist = ?";
   stmt = conn.prepareStatement(query);
   stmt.setString(1,artist);
   rs = stmt.executeQuery();
   
   while(rs.next())
   {
    retValue =rs.getString(1);
   }
   System.out.println("Book Title For " + artist + " : " + retValue);
   rs.close();
   stmt.close();
   conn.close();
   conn = null;
     
  }
  catch(Exception e1){
   if (conn!=null)
   System.out.println("getBookTitle() : Release Connection Failed! ");
   return null;
  }   
  return retValue;
} 
 
 
}

------------------------------------------------------------------------------------------------------------------------------
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
             id="urn:cd-test-ws"
>
  <isd:provider type="java"
                scope="Application"
                methods="getBookTitle"
  >
    <isd:java class="testsoap.TestWsImpl" static="false" />
  </isd:provider>

  <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
 
</isd:service>
-----------------------------------------------------------------------------------------------------------------------------

testsoap.client.TestClient.java
package testsoap.client;
 
/*
 Required due to use of URL class, required by Call Class
*/
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import testsoap.*; 


public class TestClient {
 
  public void getData(URL url, String artist) throws SOAPException {
    
 System.out.println("Listing current Books.");
    System.out.println("Book's Artist Name : " + artist);

    // Build the Call object
    Call call = new Call( );
    call.setTargetObjectURI("urn:cd-test-ws");
    call.setMethodName("getBookTitle");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
 
 // Set up parameters
    Vector params = new Vector( );
    params.addElement(new Parameter("artist", String.class, artist, null));
    call.setParams(params);

    // Invoke the call
    Response response;
 System.out.println("URL: " + url);
    response = call.invoke(url, "");

    if (!response.generatedFault( )) {
    System.out.println("3");
       Parameter returnValue = response.getReturnValue( );
       String title = (String)returnValue.getValue();
       System.out.println(" Client Test Result is (TITLE) : " + title);
    
    } else {
     System.out.println("4");
      Fault fault = response.getFault( );
      System.out.println("Error encountered: " + fault.getFaultString( ));
    }
  }
 
  public static void main(String[] args) {
    if (args.length != 2) {
      System.out.println("Usage: java testsoap.TestClient [SOAP server URL]");
      return;
    }
 
    try {
      // URL for SOAP server to connect to
      URL url = new URL(args[0]);
   String param = args[1];
  System.out.println(param);
      // List the current CDs
      TestClient cl = new TestClient( );
      cl.getData(url, param);

    } catch (Exception e) {
      e.printStackTrace( );
    }
  }
}

------------------------------------------------------------------------------------------------------


D:\soapDev\src>java -classpath d:\xerces-1_4_4\xerces.jar;d:\tomsoap\lib\mail.jar;d:\tomsoap\lib\activation.jar;d:\tomsoap\lib\soap.jar;D;\tomsoap\lib\poolman\jdbc2_0-stdext.jar;d:\tomsoap\lib\bsf.jar;d:\tomsoap\lib\db2java.zip;d:\tomsoap\lib\js.jar;D:\soapDev\src;. testsoap.client.TestClient http://localhost:8080/soap/servlet/rpcrouter "John"

Result : 
John
Listing current Books.
Book's Artist Name : John
URL: http://localhost:8080/soap/servlet/rpcrouter

Error encountered: Unable to resolve target object: testsoap.TestWsImpl

Can anybody tell me that what is happening to the classpath that i set? What is the solution for this case?
Thanks in advance.


Regards
PP





Re: java.lang.NoClassDefFoundError problem

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Frederik Uyttersprot <fr...@pandora.be> writes:

> Hello,
>
> I just started playing with XML-RPC and have the following problem.
> I'm also quite new to Java. I'm trying an example from Oreilly's Java
> & XML 2nd edition, getting the following error,
>
> D:\Java\bin\java.exe   test.server.HelloServer
> Working Directory - D:\Java\temp\
> Class Path - D:\Java\temp;d:\java\lib;d:\java\xmlrpc\xmlrpc-1.1.jar;.;d:\program
> files\Kawa\kawaclasses.zip;D:\Java\lib\tools.jar;D:\Java\jre\lib\rt.jar;D:\Java\jre\lib\i18n.jar
> java.lang.NoClassDefFoundError: test/server/HelloServer Exception in thread "main" Process Exit...

NoClassDefFoundErrors occur when a class referenced or imported by
code executing at run-time is not available (i.e. not in the
classpath).  Make sure all the classes that you're importing are in
your classpath.  If that doesn't work, make sure that all the classes
that your imports import are in the classpath at run-time.

Re: java.lang.NoClassDefFoundError problem

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Frederik Uyttersprot <fr...@pandora.be> writes:

> Hello,
>
> I just started playing with XML-RPC and have the following problem.
> I'm also quite new to Java. I'm trying an example from Oreilly's Java
> & XML 2nd edition, getting the following error,
>
> D:\Java\bin\java.exe   test.server.HelloServer
> Working Directory - D:\Java\temp\
> Class Path - D:\Java\temp;d:\java\lib;d:\java\xmlrpc\xmlrpc-1.1.jar;.;d:\program
> files\Kawa\kawaclasses.zip;D:\Java\lib\tools.jar;D:\Java\jre\lib\rt.jar;D:\Java\jre\lib\i18n.jar
> java.lang.NoClassDefFoundError: test/server/HelloServer Exception in thread "main" Process Exit...

NoClassDefFoundErrors occur when a class referenced or imported by
code executing at run-time is not available (i.e. not in the
classpath).  Make sure all the classes that you're importing are in
your classpath.  If that doesn't work, make sure that all the classes
that your imports import are in the classpath at run-time.