1 创建项目,web项目和webservice项目都可以,写服务类直接实现
package com.test.webservice;
public class Counter
{
public int add(int num1,int num2)
{
return num1 + num2;
}
}
2 创建webservice
选择jax-ws和从java类中创建策略
填写代理类名称,soap风格,是否生成wsdl和命名空间,本例全为默认,点击完成,创建后的项目目录如下
此时,右键项目名,选择构建路径->配置构建路径->source选项卡,发现会多出一个源码文件夹.apt_generated
如果你在项目中找不到这个源码包,可以在Package Explorer右上角位置找到向下的小三角,如下图最右边
点击小三角,出现下图,将*.resource去掉,
会看到.apt_generated源码包下的文件,
将项目部署后会出现如下问题:
1 启动服务器后,报如下错误:
解决方法:在项目的构建路径中加入jax-ws的相关jar包
2 出现如下错误信息,表示.apt_generated源码包下没有自动生成jax-ws相应的类,所以提示是否已经用apt生成了。
信息: WSSERVLET12: JAX-WS context listener initializing
2012-3-1 21:58:41 com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
严重: WSSERVLET11: failed to parse runtime descriptor: runtime modeler error: Wrapper class com.test.webservice.jaxws.Add is not found. Have you run APT to generate them?
com.sun.xml.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class com.test.webservice.jaxws.Add is not found. Have you run APT to generate them?
如果生成了,部署到tomcat的项目文件中会在服务类下生成一个jaxws包:
对本例而言,jaxws中有如下文件:
解决办法:确保构建路径中的source选项卡中选择了.apt_generated,如果还没生成,clean下项目应该就没问题了
3 误删除了自动生成的.apt_generated源码包
When the Feature Pack for Web Services 1.0 facet is enabled, the .apt_generated folder is created in the Web project. If this folder is accidentally deleted, it is automatically restored, but it no longer has the properties of a source folder. Thus, the classes in this folder are not built into the class path for the Web project and ClassNotFound exceptions might occur after the Web project is deployed to the server.
Resolving the problemAfter the folder is deleted, it is not present in the Java™ 2 Platform, Enterprise Edition (J2EE) perspective. Follow these steps to restore the source folder:
解决办法:
1.Open the Resource perspective. You should see the .apt_generated folder, which is automatically regenerated.
2.Open the .settings/org.eclipse.wst.common.component file.
3.From the Source view, delete the following line:
<wb-resource deploy-path="/WEB-INF/classes" source-path="/.apt_generated"/>
4.Right-click the project and select Properties > Java Build Path
5.On the Source tab, add .apt_generated to the list of Source folders.
发布成功后,会出现如下界面: