i m using mtom feature in jaxws web service to send image from server to client and i m getting the following error pls i apreciate any help.
error is Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/x
ml/stream/buffer/XMLStreamBuffer
at com.sun.xml.ws.api.addressing.AddressingVersion.<init>(AddressingVers
ion.java:436)
at com.sun.xml.ws.api.addressing.AddressingVersion.<init>(AddressingVers
ion.java:67)
at com.sun.xml.ws.api.addressing.AddressingVersion$1.<init>(AddressingVe
rsion.java:146)
code is

package services;
import java.awt.Image;
import java.net.URL;
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.ws.WebServiceException;
import java.awt.*;
import javax.swing.*;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.soap.MTOM;
@WebService(serviceName="ImageService", portName="ImagePort", name="Image" ,wsdlLocation="ImageService.wsdl")
@BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)
public class ImageService {  @Resource    private WebServiceContext wsContext;    
 @WebMethod    public java.awt.Image getJavaImage() 
{wsContext.getMessageContext().put(com.sun.xml.ws.developer.JAXWSProperties.MTOM_THRESHOLOD_VALUE,0); 
 String path = "C:\\pictures\\07062010028.jpg";
 Image img = Toolkit.getDefaultToolkit().getImage(path);        
return img;    
}
}
import services.Image;
import services.ImageService;
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import javax.xml.ws.soap.MTOMFeature;
import java.util.Map;
import javax.activation.DataHandler;
import javax.xml.ws.BindingProvider;
import java.io.InputStream;
import javax.xml.ws.*;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.soap.MTOM;
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.SOAPBinding;
import javax.xml.bind.JAXBContext;
import javax.xml.ws.Service;
import javax.xml.ws.BindingProvider;
import java.io.*;
import java.net.*;
import java.util.*;
import java.awt.Image.*;
import javax.xml.soap.*;
import javax.activation.DataHandler;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Holder;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.SOAPBinding;
import javax.xml.ws.WebServiceRef;
import javax.swing.*;
import java.lang.*;
public class ImageFrame { 
  public ImageFrame() 
{        
      
    

}
public static void main(String args[]) 
{        
java.awt.EventQueue.invokeLater(new Runnable() 
{            
public void run() 
{
   try 
{ // Call Web Service Operation    
       
JButton jButton1 = new JButton();       
jButton1.setText("Java Button");   
ImageService service = new ImageService();            
Image port = service.getImagePort(new MTOMFeature()); 
SOAPBinding binding = (SOAPBinding) ((BindingProvider)port).getBinding();
binding.setMTOMEnabled(true);            
java.awt.Image result = port.getJavaImage(); 
JFrame f=new JFrame();           
System.out.println();            
jButton1.setIcon(new ImageIcon(result));
f.add(jButton1);    
f.setVisible(true);    
} catch (Exception ex) 
{            
ex.printStackTrace();        
}             
            
}        
});    
}    
}

NoClassDefFoundError: com/sun/xml/stream/buffer/XMLStreamBuffer

Where is the missing class? Is there a missing jar file?
Is the jar file with that class on the classpath?

yes of course all jar files are on class path.i put the whole library jaxws-rt.jar and all necessary jar files in the path related to environment variable.
regards

Did you check if the missing class file was in one of the jar files and that the class file was on the proper path in the jar file?

yes i checked up it is in jaxws-ri.jar,or jaxws-api.jar.i searched a lot but not finding a solution.

it is in jaxws-ri.jar,or jaxws-api.jar

That is a strange answer. Either it is in one or both or it is in neither.

no it is in one of them,sorry it is exactly in jaxws-ri.jar i entereed to environment variables and i put the path of this jar file.and i m getting the same runtime error!!

Are you sure the program you are using uses the OSs environment variables to find classes? Can it have its own classloader that finds it class files in other locations?

no i m sure bcs i uses many other jar files in java with different applications and every thing goes well.but in this code i can't find what is the problem??

no i m sure bcs i uses many other jar files in java with different applications and every thing goes well.but in this code i can't find what is the problem??

You need to have 'streambuffer.jar' file in your runtime classpath. Check whether you have that JAR included at both client and server.

what do u mean on both server and client??u r right i added streambuffer.jar to the environment variables as i am running the client and server in the same machine.i m using appache tomcat as web server and i put my client and server code.do i need any thing else???

> what do u mean on both server and client?

The client is a Java Swing application, no? Look at the stack trace you posted in your first post. The client invokes a webservice and hence needs to have access to all the runtime JARs required by a webservice client.

Also, don't mess around with environment variables when setting classpath. In case of a web application, use WEB-INF/lib directory. In case of a standalone client application, package the dependent JAR's in a separate directory and include in on the classpath using -cp switch.

This article has been dead for over six months. Start a new discussion instead.