使用Java API for XML-based Web services(JAX-WS)开发WebLogic Web服务的简单例子。
环境
- WebLogic 12C
- VSCode
做成简单的Hello World Web Service
1. 设定WebLogic Server环境
■windows
DOMAIN_HOME: 例 D:\Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain
cd DOMAIN_HOME\binsetDomainEnv.cmd
■linux
DOMAIN_HOME: 例:/home/weblogic/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain
cd DOMAIN_HOME
. bin/setDomainEnv.sh
2. 做成project目录
mkdir myExamples
mkdir myExamples/hello_word
cd myExamples/hello_word
mkdir src
mkdir src/examples
mkdir src/examples/webservices
mkdir src/examples/webservices/hello_world
3. 实现web服务
做成实现Web Service的JWS文件。
在mkdir src/examples/webservices/hello_world下,新建文件HelloWorldImpl.java,内容参考如下:
package examples.webservices.hello_world;// Import the @WebService annotation
import javax.jws.WebService;
@WebService(name="HelloWorldPortType", serviceName="HelloWorldService")
/*** This JWS file forms the basis of simple Java-class implemented WebLogic* Web Service with a single operation: sayHelloWorld*/
public class HelloWorldImpl {// By default, all public methods are exposed as Web Services operationpublic String sayHelloWorld(String message) {try {System.out.println("sayHelloWorld:" + message);} catch (Exception ex) { ex.printStackTrace(); }return "Here is the message: '" + message + "'";}
}
@WebService注解指定该Java类实现了名为HelloWorldService的Web服务