1 創(chuàng)建項目,web項目和webservice項目都可以,寫服務類直接實現(xiàn)

package com.test.webservice;

public class Counter
{
 public int add(int num1,int num2)
 {
  return num1 + num2;
 }
}

2 創(chuàng)建webservice

myeclipse10創(chuàng)建jax-ws方式的webservice(一)
 選擇jax-ws和從java類中創(chuàng)建策略

myeclipse10創(chuàng)建jax-ws方式的webservice(一)
 填寫代理類名稱,soap風格,是否生成wsdl和命名空間,本例全為默認,點擊完成,創(chuàng)建后的項目目錄如下

myeclipse10創(chuàng)建jax-ws方式的webservice(一)


myeclipse10創(chuàng)建jax-ws方式的webservice(一)

 

此時,右鍵項目名,選擇構(gòu)建路徑->配置構(gòu)建路徑->source選項卡,發(fā)現(xiàn)會多出一個源碼文件夾.apt_generated

如果你在項目中找不到這個源碼包,可以在Package Explorer右上角位置找到向下的小三角,如下圖最右邊

myeclipse10創(chuàng)建jax-ws方式的webservice(一)
點擊小三角,出現(xiàn)下圖,將*.resource去掉,
myeclipse10創(chuàng)建jax-ws方式的webservice(一)
會看到.apt_generated源碼包下的文件,

myeclipse10創(chuàng)建jax-ws方式的webservice(一)

將項目部署后會出現(xiàn)如下問題:

myeclipse10創(chuàng)建jax-ws方式的webservice(二)

 

1 啟動服務器后,報如下錯誤:
解決方法:在項目的構(gòu)建路徑中加入jax-ws的相關(guān)jar包

myeclipse10創(chuàng)建jax-ws方式的webservice(二)

myeclipse10創(chuàng)建jax-ws方式的webservice(二)


2 出現(xiàn)如下錯誤信息,表示.apt_generated源碼包下沒有自動生成jax-ws相應的類,所以提示是否已經(jīng)用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包:

myeclipse10創(chuàng)建jax-ws方式的webservice(二)
對本例而言,jaxws中有如下文件:

myeclipse10創(chuàng)建jax-ws方式的webservice(二)
解決辦法:確保構(gòu)建路徑中的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.
發(fā)布成功后,會出現(xiàn)如下界面:

myeclipse10創(chuàng)建jax-ws方式的webservice(二)

 今天你菊子曰了么?