0

I am attempting to build my first Java web service using this tutorial http://www.ibm.com/developerworks/webservices/tutorials/ws-jax/ws-jax.html but it produces errors at a certain point that I cannot resolve. The tutorial includes a download and even when I simply use the relevant file from the download its still gives me the errors. All java classes have complied until this point. The OrderProcessService class has complied fine and I have checked all spelling of files and folder names but still it is as if the java compiler cannot see the OrderProcessService class. What am I doing wrong here? I have copied in the OrderProcessService class and the OrderWebServicePublisher class. The other classes in the bean directory, such as Customer and Address are just POJO's. Here is the error;

enter image description here

The OrderProcessService.java

package com.ibm.jaxws.tutorial.service;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import com.ibm.jaxws.tutorial.service.bean.OrderBean;


// JWS annotation that specifies that the portType name of the 
// Web service is "OrderProcessPort" the service name is 
// "OrderProcess" and the targetNamespace used in the generated
// WSDL is "http://jaxws.ibm.tutorial/jaxws/orderprocess"

@WebService(serviceName = "OrderProcess",
  portName = "OrderProcessPort", 
  targetNamespace = "http://jaxws.ibm.tutorial/jaxws/orderprocess")

// JWS annotation that specifies the mapping of the service onto the 
// SOAP message protocol.  In particular, it specifies that the SOAP  
// messages
// are document literal

@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL,
  parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)

public class OrderProcessService{

@WebMethod
public OrderBean processOrder(OrderBean orderBean){

// Do processing
System.out.println("processOrder called for customer"
  + orderBean.getCustomer().getCustomerId());

// Items ordered are
if(orderBean.getOrderItems() != null) {
  System.out.println("Number of items is"
  + orderBean.getOrderItems().length);
}

// Process Order
// Set the order ID
orderBean.setOrderId("A1234");

return orderBean;

}

}

The OrderWebServicePublisher.java

package com.ibm.jaxws.tutorial.service.publish;

import javax.xml.ws.Endpoint;

import com.ibm.jaxws.tutorial.service.OrderProcessService;

public class OrderWebServicePublisher {

   public static void main(String[] args) {

     Endpoint.publish("http://localhost:8080/OrderProcessWeb/orderprocess",
          new OrderProcessService());

     System.out.println("The web service is published at   
       http://localhost:8080/OrderProcessWeb/orderprocess");

     System.out.println("To stop running the web service , terminate the  
       java process");

    }

 }
JFPicard
  • 4,659
  • 3
  • 16
  • 38
AJF
  • 1,519
  • 4
  • 19
  • 42

3 Answers3

1

Looks like you are running from the command line. You will need to specify the classpath of all required classes.

Instead of doing

javac com\....\OrderWebService.java

do

javac -cp <path to your OrderProcessorService> com\...\OrderWebService.Java

More examples please see Setting multiple jars in java classpath

Community
  • 1
  • 1
TR1
  • 303
  • 1
  • 9
  • Thanks but I tried the following but it still gave the same errors C:\JAXWS-Tutorial> javac -cp C:\JAXWS-Tutorial\com\ibm\jaxws\tutorial\service\OrderProcessService.java com\ibm\jaxws\tutorial\service\publish\OrderWebServicePublisher.java – AJF Nov 19 '15 at 17:10
  • The part '' is the root directory (root of your pacakages) of your java classes (.class files) and not individual .java files. So it should be javac -cp C:\JAXWS-Tutorial\ com\ibm\....\OrderWebServicePublisher.java – TR1 Nov 19 '15 at 17:16
  • Thanks. No errors this time. Can I ask why it needs to know this when all other classes compiled okay? Is it because when I compiled the OrderProcessService class it compiled the POJO's in the bean sub folder at the same time? – AJF Nov 19 '15 at 17:47
  • When you are compiling OrderWebService.java it needs to know where it can find OrderProcessorService (as OrderWebService uses OrderProcessorService). The classes that compiled successfully - possibly there are no references to other classes - hence can compile on it's own. – TR1 Nov 19 '15 at 18:38
0

I am going to guess you haven't setup the classpath correctly? If running from command line utilize the -cp option. If running from IDE, define accordingly.

schacherer
  • 21
  • 3
0

Did you write this in an IDE or a text editor. An IDE like Eclipse would have caught it. But usually this error is seen in situation like a jar is missing in your classpath. But it seems you have the java file and compiled it again. For your case when I looked at the link in your question : did you run:

wsgen -cp . com.ibm.jaxws.tutorial.service.OrderProcessService -wsdl ?

SomeDude
  • 7,432
  • 4
  • 19
  • 33