Main Tutorials

Wrapper class package.jaxws.methodName is not found. Have you run APT to generate them?

Problem

In JAX-WS development, when following service endpoint is deploying,

File : HelloWorld.java

 
package com.mkyong.ws;
//Service Endpoint Interface
@WebService
public interface HelloWorld{
 
	@WebMethod String getHelloWorldAsString();
}

File : HelloWorldImpl.java

 
//Service Implementation
package com.mkyong.ws;
@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
 
	@Override
	public String getHelloWorldAsString() {
		//...
	}
 
}

It hits following error message immediately?


Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: 
	runtime modeler error: 

        Wrapper class com.mkyong.ws.jaxws.GetHelloWorldAsString is not found. 
        Have you run APT to generate them?

	at com.sun.xml.internal.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:256)
	//...

Solution

The service endpoint interface is not annotated with any @SOAPBinding, so, it uses the default document style to publish it. For human readability, you can rewrite it as following :

 
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL)
public interface HelloWorld{
 
	@WebMethod String getHelloWorldAsString();
}

In document style, you need to use “wsgen” tool to generate all the necessary JAX-WS portable artifacts (mapping classes, wsdl or xsd schema) for the service publication.

wsgen command

The wsgen command is required to read the service endpoint implementation class :


wsgen -keep -cp . com.mkyong.ws.HelloWorldImpl

It generates two classes for a single getHelloWorldAsString() method, under package.jaxws folder.

  1. GetHelloWorldAsString.java
  2. GetHelloWorldAsStringResponse.java

Copy those classes to correct folder, in this case, it’s “com.mkyong.ws.jaxws“. Try publish it again.

Reference

  1. wsgen tool documentation

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Umanath M
9 years ago

please add “import javax.jws.soap.SOAPBinding.Use;” in interface HelloWorld to avoid Use.LITERAL an enum annotation value must be an enum constant

Raja
6 years ago

Hi I am facing “com.sun.xml.internal.ws.model.RuntimeModelerException: class: .com.mytest.ws.HelloWorld could not be found” , when i run the publisher file.

Below is my HelloWorld webservice interface code:
@WebService
@SOAPBinding(style = Style.RPC,use= SOAPBinding.Use.LITERAL)
public interface HelloWorld {

@WebMethod public String getHelloWorldAsString(String name);
}

Below is my HelloWorldImpl code
@WebService(endpointInterface = “.com.mytest.ws.HelloWorld”)
public class HellowWorldImpl implements HelloWorld {

@Override
public String getHelloWorldAsString(String name){

return “com.mytest.ws.HelloWorld!”+name;

}
}

Below is my publisher code
public class HelloWorldPublisher {

public static void main(String []args){

Endpoint.publish(“http://localhost:7779/ws/hello”,new HellowWorldImpl());
}
}

PS::I have tride using wsgen as you mentioned in this blog. But its not working. its suggesting llike below.

D:AutomationWebServiceTestsrccommytestws>wsgen -keep -cp . com.mytest.ws.HelloWorldImpl
Class not found: “com.mytest.ws.HelloWorldImpl”

Usage: WSGEN [options]

where [options] include:
-classpath specify where to find input class files and wsgen extensions
-cp specify where to find input class files and wsgen extensions
-d specify where to place generated output files
-encoding specify character encoding used by source files
-extension allow vendor extensions – functionality not specified
by the specification. Use of extensions may
result in applications that are not portable or
may not interoperate with other implementations
-help display help
-J pass this option to javac
-keep keep generated files
-r resource destination directory, specify where to
place resouce files such as WSDLs
-s specify where to place generated source files
-verbose output messages about what the compiler is doing
-version print version information
-fullversion print full version information
-wsdl[:protocol] generate a WSDL file. The protocol is optional.
Valid protocols are [soap1.1, Xsoap1.2],
the default is soap1.1.
The non standard protocols [Xsoap1.2]
can only be used in conjunction with the
-extension option.
-inlineSchemas inline schemas in the generated wsdl. Must be
used in conjunction with the -wsdl option.
-servicename specify the Service name to use in the generated WSDL
Used in conjunction with the -wsdl option.
-portname specify the Port name to use in the generated WSDL
Used in conjunction with the -wsdl option.
-x specify External Web Service Metadata xml descriptor

Extensions:
-Xnocompile do not compile generated Java files

Examples:
wsgen -cp . example.Stock
wsgen -cp . example.Stock -wsdl -servicename {http://mynamespace}MyService

Bahniman Roy
9 years ago

It appears that the error is JRE dependent. I swapped the JRE and the wrapper classes were auto generated – below is an excerpt from the log when Endpoint.publish(…) is invoked.

INFO: Dynamically creating request wrapper ….

Satish
11 years ago

I was reading the document style web service and I did not get this error.. I am using jdk 7. For me with out the artifacts, document style is running fine..

I got a bit confused.. Please clarify.

Gezzer
11 years ago

Thanks!
SO MUCH!!!