Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java "Class file contains wrong class" error

I'm trying to make a console application to test my webservice. I successfully deployed a webservice at http://localhost:8080/WS/myWS and i made proxy classes with wsimport:

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

Now my webservice classes are located in bin/mywebservice/ and i'm trying to compile my client class with classpath = ./

Here's the source code of my class:

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

And i have error:

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.

please help, what's wrong with myClass_Service? i swear, myClass_Service.class exists in .\bin\mywebservice\

like image 803
yur15t Avatar asked Aug 16 '26 03:08

yur15t


2 Answers

You're incorrectly including the bin in the import declaration.

Rather put bin on the classpath and correct the import.

Unless (the poorly-named) myClass_Service.java file is package bin.mywebservice (which it isn't, according the the error message), you're trying to correct the problem in the wrong place.

like image 52
Dave Newton Avatar answered Aug 18 '26 16:08

Dave Newton


It looks like the generated class has a package mywebservice, not bin.mywebservice. Make sure the bin directory is on the classpath, and drop bin from the packages.

like image 25
Kaleb Brasee Avatar answered Aug 18 '26 16:08

Kaleb Brasee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!