Web Services java“类文件包含错误的类”错误

46scxncf  于 2023-06-23  发布在  Java
关注(0)|答案(4)|浏览(184)

我正在尝试制作一个控制台应用程序来测试我的Web服务。我成功地在http://localhost:8080/WS/myWS上部署了一个Web服务,并使用wsimport创建了代理类:

wsimport -d bin -s src http://localhost:8080/WS/myWS?wsdl

现在我的WebService类位于bin/myWebService/中,我正尝试用classpath = ./编译我的客户端类
下面是我的类的源代码:

import bin.mywebservice.myClass_Service;
public class TesterApp{
    public static void main (String args[])
    {    
        myClass_Service service = new myClass_Service(); 
    }
}

我有错误:

TesterApp.java:1: error: cannot access myClass_Service
import bin.mywebservice_Service.myClass;
                               ^
  bad class file: .\bin\mywebservice\myClass_Service.class
    class file contains wrong class: mywebservice.myClass_Service
    Please remove or make sure it appears in the correct subdirectory of the classpath.

请帮助,myClass_Service有什么问题?我发誓myClass_Service.class存在于.\bin\mywebservice\

cgh8pdjw

cgh8pdjw1#

您错误地将bin包含在import声明中。
而是将bin放在类路径上并更正import
除非(名称不好的)myClass_Service.java文件是package bin.mywebservice(根据错误信息,它不是),否则您试图在错误的地方纠正问题。

fdx2calv

fdx2calv2#

看起来生成的类有一个包mywebservice,而不是bin.mywebservice。确保bin目录在类路径上,并从包中删除bin

eqoofvh9

eqoofvh93#

如果你确定你的文件位于bin目录下,你已经检查了调用mywebservice.myClass_Service的类文件
bin目录下也一样。因为当两个文件的位置不一样时,就会出错。或者您可以在代码顶部查看您的包裹位置。
Package 箱;
看看并比较这两个。

tv6aics1

tv6aics14#

如果您正在使用软件包,此makefile可能会有所帮助:

CLASS_PATH = ../bin

vpath %.class $(CLASS_PATH)

all : HelloJNI.h

HelloJNI.h : com/my/package/HelloJNI.class
    javah -classpath $(CLASS_PATH) com.my.package.$*

相关问题