Class not found exception when trying to create web service client

I am trying to consume a web service from a Java client.

I created classes using wsimport:

wsimport -keep -verbose http://localhost:5382/Service1.svc?wsdl

      

The code looks something like this:

private String CreateSalesforceIssue() {

    IssueService service = new IssueService();
    IIssueService binding = service.getBasicHttpBindingIIssueService();

    String issueID = binding.createIssue(type, description, steps, 
                                                    expected, workaround, storage, 
                                                    docType, actions, tools, external, 
                                                    repeatability, workaroundType, severity, 
                                                    pmSeverity, products, extensions, versions, 
                                                    os, status, project, resolution, fixversions);

    return issueID;
}

      

When it hits this line:

    IssueService service = new IssueService();

      

Going into the code far enough and it ends up in javax.xml.ws.spi.Provider and doesn't work there.

On

public static Provider provider() {
    try {
        Object provider =
                FactoryFinder.find(JAXWSPROVIDER_PROPERTY,
                DEFAULT_JAXWSPROVIDER);
        if (!(provider instanceof Provider)) {
            Class pClass = Provider.class;
            String classnameAsResource = pClass.getName().replace('.', '/') + ".class";
            ClassLoader loader = pClass.getClassLoader();
            if(loader == null) {
                loader = ClassLoader.getSystemClassLoader();
            }
            URL targetTypeURL  = loader.getResource(classnameAsResource);
            throw new LinkageError("ClassCastException: attempting to cast" + 
                   provider.getClass().getClassLoader().getResource(classnameAsResource) +
                   "to" + targetTypeURL.toString() );
        }
        return (Provider) provider;
    } catch (WebServiceException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new WebServiceException("Unable to createEndpointReference Provider", ex);
    } 
}

      

on this line:

if (!(provider instanceof Provider)) {

      

with ClassNotFoundException: provider com.sun.xml.ws.spi.ProviderImpl

I feel like I'm missing something, unfortunately I'm not sure what ... Do I need to initialize the provider somewhere?

+3


source to share


1 answer


You must add the class Provider

to classpath

. If you are using IDE

, you can easily add a library by right clicking on the library and choosing "add Jar file" (or something!). But if you try to compile and run your application through terminal

, use the following commands:

javac -d [bin folder] -cp [jar files] [java source files]
java -classpath [jar files] [Main class]

      



you have to split the jar files using :

on Linux and MAC OS and ;

MS Windows. As you said, this is a web service, I think you are using IDE

and the first solution might help you.

PS If you added this jar file to the classpath and this one exception

repeats, add this jar file to your webserver / container library directory. (for example, a lib

folder in tomcat

.

+1


source







All Articles