SAngraM
SAngraM

Reputation: 41

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 + ".";
    }
}

Upvotes: 4

Views: 14631

Answers (3)

jose liza
jose liza

Reputation: 41

in the pom.xml file add

<dependency>
  <groupId>javax.jws</groupId>
  <artifactId>javax.jws-api</artifactId>
  <version>1.1</version>
</dependency>

Upvotes: 2

Anish Panthi
Anish Panthi

Reputation: 1032

Use javax.jws-api artifact instead and it will solve your problem. Below is the gradle implementation:

implementation 'javax.jws:javax.jws-api:1.1'

Check the version and use the latest.

It is not recommended to downgrade the Java version just to fix the issue.

Upvotes: 1

jcompetence
jcompetence

Reputation: 8383

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

Upvotes: 3

Related Questions