【问题标题】:java "Class file contains wrong class" errorjava“类文件包含错误的类”错误
【发布时间】:2011-12-04 17:42:12
【问题描述】:

我正在尝试制作一个控制台应用程序来测试我的网络服务。 我在http://localhost:8080/WS/myWS 成功部署了一个网络服务 我用 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\

【问题讨论】:

    标签: java web-services classpath webservice-client wsimport


    【解决方案1】:

    您在 import 声明中错误地包含了 bin

    而是将bin 放在类路径中并更正import

    除非(名称不佳的)myClass_Service.java 文件是 package bin.mywebservice(根据错误消息,它不是),否则您正试图在错误的位置纠正问题。

    【讨论】:

    • 真丢脸。我应该从一开始就开始学习java。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      如果您使用软件包,此 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.$*
      

      【讨论】:

        猜你喜欢
        • 2015-12-24
        • 2014-09-09
        • 2014-09-10
        • 2015-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多