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.
發布成功后,會出現如下界面:
