Java编译器无法看到我的类

时间:2015-11-19 15:54:08

标签: java web-services

我正在尝试使用本教程http://www.ibm.com/developerworks/webservices/tutorials/ws-jax/ws-jax.html构建我的第一个Java Web服务,但它在某个我无法解决的点上产生错误。该教程包括下载,即使我只是使用下载中的相关文件,它仍然给我错误。直到这一点,所有java类都已遵守。 OrderProcessService类已经编译得很好,我检查了所有文件和文件夹名称的拼写但仍然好像java编译器看不到OrderProcessService类。我在这做错了什么?我已经复制了OrderProcessService类和OrderWebServicePublisher类。 bean目录中的其他类,例如Customer和Address,只是POJO' s。这是错误;

enter image description here

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;

}

}

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");

    }

 }

3 个答案:

答案 0 :(得分:1)

看起来您正在从命令行运行。您需要指定所有必需类的类路径。

而不是做

javac com\....\OrderWebService.java

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

更多示例请参阅Setting multiple jars in java classpath

答案 1 :(得分:0)

我猜你没有正确设置类路径?如果从命令行运行,则使用-cp选项。如果从IDE运行,请相应地进行定义。

答案 2 :(得分:0)

您是在IDE或文本编辑器中编写的吗?像Eclipse这样的IDE会抓住它。但通常在类路径中缺少jar的情况下会出现此错误。但似乎你有java文件并再次编译它。对于您查看问题中链接的情况:您是否运行过:

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