努力,成长,提高

在追求中进步
数据加载中……
用myeclipse开发oc4j第一个webservice的简单示例

新建project.如下图选择,

建立好以后的目录树如图:

 

  1. 添加新的webservice 接口和实现类。

依次选择File->New->Other

如图



点击Finish.

  1. 双击编辑HelloWorldImpl.java

代码如下:

public class HelloWorldImpl implements IHelloWorld {

 

      
public String example(String message) {

            
return "Hello World" + message;

      }


 

}



  1. 修改WebRoot->WEB-INF->web.xml如下

 

 

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

 xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet>

    
<servlet-name>helloworld</servlet-name>

    
<servlet-class>oracle.j2ee.ws.StatelessJavaRpcWebService</servlet-class>

    
<init-param>

      
<param-name>class-name</param-name>

      
<param-value>HelloWorldImpl</param-value>

    
</init-param>

    
<init-param>

      
<param-name>interface-name</param-name>

      
<param-value>IHelloWorld</param-value>

    
</init-param>

  
</servlet>

  
<servlet-mapping>

    
<servlet-name>helloworld</servlet-name>

    
<url-pattern>/HelloWorld</url-pattern>

  
</servlet-mapping>

</web-app>

 

  1. 添加新的build.xml

内容如下:

<?xml version="1.0" encoding="UTF-8"?>

 

<project basedir="." default="war" name="bid">

      
<property name="app-name" value="bid" />

      
<property name="release-version" value="20060720-1549" />

      
<property name="src" value="src" />

      
<property name="dist" value="dist" />

      
<property name="classes" value="WebRoot/WEB-INF/classes" />

      
<property name="lib" value="WebRoot/WEB-INF/lib" />

      
<property name="ext-lib" value="ext-lib" />

      
<property name="charset" value="UTF-8" />

      
<property name="javadoc-packagenames"

            value
="com.safemore.bid,com.safemore.bid.bid,com.safemore.bid.common,com.safemore.bid.issue,com.safemore.bid.logon,com.safemore.bid.util" />

 

      
<patternset id="resources">

            
<include name="**/*.jpe" />

            
<include name="**/*.jpeg" />

            
<include name="**/*.rmf" />

            
<include name="**/*.wav" />

            
<include name="**/*.midi" />

            
<include name="**/*.mid" />

            
<include name="**/*.au" />

            
<include name="**/*.gif" />

            
<include name="**/*.png" />

            
<include name="**/*.jpg" />

            
<include name="**/*.aiff" />

            
<include name="**/*.properties" />

            
<include name="**/*.txt" />

            
<include name="**/*.xml" />

      
</patternset>

 

      
<path id="classpath">

            
<pathelement location="${dist}" />

            
<fileset dir="${lib}">

                  
<include name="*.jar" />

            
</fileset>

            
<fileset dir="${ext-lib}">

                  
<include name="*.jar" />

            
</fileset>

      
</path>

 

      
<target name="init">

            
<mkdir dir="${dist}" />

            
<mkdir dir="${classes}" />

      
</target>

 

      
<target name="war" depends="resource, jar">

            
<!--touch file="WEB-INF/web.xml"/-->

            
<war compress="false" destfile="${dist}/${app-name}-${release-version}.war"

                  webxml
="WebRoot/WEB-INF/web.xml">

                  
<fileset dir="WebRoot">

                        
<include name="**/*.*" />

                        
<exclude name="WEB-INF/" />

                  
</fileset>

                  
<fileset dir="WebRoot">

                        
<include name="WEB-INF/*.*" />

                        
<exclude name="WEB-INF/web.xml" />

                        
<exclude name="WEB-INF/${app-name}.xml" />

                        
<!--exclude name="lib/" /-->

                  
</fileset>

                  
<!--lib dir="${lib}"-->

                  
<include name="*.jar" />

                  
<!--/lib-->

                  
<!--

                        <lib dir="${dist}"> <include name="*.jar" /> </lib>

                  
-->

                  
<classes dir="${classes}" />

            
</war>

      
</target>

 

      
<target name="resource">

            
<copy todir="${classes}">

                  
<fileset dir="${src}">

                        
<patternset refid="resources" />

                  
</fileset>

            
</copy>

      
</target>

 

      
<target name="clean">

            
<delete dir="${classes}" />

            
<delete dir="${dist}" />

      
</target>

 

      
<target name="compile" depends="init">

            
<javac classpathref="classpath" debug="true" deprecation="false"

                  destdir
="${classes}" nowarn="false" encoding="${charset}">

                  
<src path="${src}" />

            
</javac>

      
</target>

 

      
<target name="jar" depends="resource, compile, init">

            
<jar compress="false" destfile="${dist}/${app-name}-${release-version}.jar">

                  
<fileset dir="${classes}">

                        
<include name="**/*.class" />

                        
<patternset refid="resources" />

                  
</fileset>

            
</jar>

      
</target>

 

      
<target name="rejar" depends="clean, jar" />

 

      
<target name="ear" depends="war">

            
<ear destfile="${dist}/${app-name}-${release-version}.ear" appxml="META-INF/application-j1.3.xml">

                  
<fileset dir="${dist}" includes="${app-name}-${release-version}.war" />

            
</ear>

      
</target>

 

      
<target name="release" depends="war">

            
<zip destfile="${dist}/${app-name}-${release-version}.zip">

                  
<zipfileset dir="${dist}" includes="${app-name}-${release-version}.war"

                        prefix
="." />

                  
<zipfileset dir="db" includes="*.*" prefix="db" />

                  
<zipfileset dir="doc" includes="*.*" prefix="doc" />

            
</zip>

      
</target>

 

      
<target name="javadoc">

            
<javadoc encoding="${charset}" charset="${charset}" access="public"

                  author
="true" destdir="${dist}/javadoc" nodeprecated="false"

                  nodeprecatedlist
="false" noindex="false" nonavbar="false" notree="false"

                  source
="1.5" splitindex="true" use="true" version="true"

                  packagenames
="${javadoc-packagenames}" sourcepath="${src}"

                  classpathref
="classpath" />

      
</target>

</project>

 

  1. 到你的hello的系统目录下面去,在与build.xml同级的目录下面运行ant
  2. 然后再myeclipse里面刷新工程会看到多了一个dist目录,这下面就有我们需要的war文件。
  3. 启动oc4j,在浏览器中输入http://localhost:8888/em/

然后登录。

  1. 依次选择Applications->deploy->

 

Browse选择你的dist下面的那个war文件,然后选择next.

Application Name随便添,Context-Root填写HelloWorld

然后下一步,deploy.

  1. 在浏览器中输入http://localhost:7788/HelloWorld/HelloWorld

看看效果。点击 example,parma0输入 Me. 点击 Invoke,怎么样,xml成功返回了。恭喜你,第一个servlet成功了。

posted on 2009-02-11 10:21 孔阳 阅读(1196) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: