Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import javax.jws.webservice for @WebService annotation

I am working on Eclipse IDE and creating a web-service program. IDE gives an error while importing import javax.jws.WebService; import javax.jws.WebMethod; error shows the import javax.jws can not be resolved

import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService
public class Hello {
    private final String message = "Hello, ";

    public Hello() {
    }

    @WebMethod
    public String sayHello(String name) {
        return message + name + ".";
    }
}
like image 993
SAngraM Avatar asked Nov 01 '25 09:11

SAngraM


2 Answers

Check that your project has appropriate JDK.

Right click on the project --> Properties --> Compiler

I created your file in Java8, and it worked.

enter image description here

like image 59
JCompetence Avatar answered Nov 02 '25 23:11

JCompetence


in the pom.xml file add

<dependency>
  <groupId>javax.jws</groupId>
  <artifactId>javax.jws-api</artifactId>
  <version>1.1</version>
</dependency>
like image 31
jose liza Avatar answered Nov 02 '25 23:11

jose liza