Weblogic - Simple Web Service (Hello World) with a JWS (Java Web Service) class


Steps on how to create a Java Web Service with the bottom-up Java Web Service file annotation method (ie from a java class and not from the WSDL file) on the weblogic application server. The web service is simple because it return only a string datatype.


JWS File

The sample JWS file shows a Java class called HelloWorldImpl that contains a single public method, sayHelloWorld(String). The @WebService annotation specifies that the Java class implements a Web service called HelloWorldService. By default, all public methods are exposed as operations.

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 operation
  public String sayHelloWorld(String message) {
  try {
    System.out.println("sayHelloWorld:" + message);
  } catch (Exception ex) { ex.printStackTrace(); }

    return "Here is the message: '" + message + "'";

Ant Build File

The following full ant build.xml file contains :

  • properties (variable), such as ${ear-dir}
  • Ant task such as taskdef <taskdef name=“jwsc”…> that specify the full Java classname of the task
  • target such as <target name=“build-service”> that is a jwsc WebLogic Web service Ant task that:
    • generates the supporting artifacts,
    • compiles the user-created and generated Java code,
    • and archives all the artifacts into an Enterprise Application EAR file that you later deploy to WebLogic Server.

Other present in the ant build file are:

  • clean,
  • undeploy,
  • client,
  • and run.

You specify the type of Web service (JAX-WS) that you want to create using type=“JAXWS”.

<project name="webservices-hello_world" default="all">
  <!-- set global properties for this build -->
	<property name="wls.username" value="weblogic" />
	<property name="wls.password" value="weblogic12" />
	<property name="wls.hostname" value="localhost" />
	<property name="wls.port" value="7001" />
	<property name="wls.server.name" value="myManagedServer" />
	<property name="wls.server.port" value="7003" />
	<property name="ear.deployed.name" value="helloWorldEar" />
	<property name="example-output" value="output" />
	<property name="ear-dir" value="${example-output}/helloWorldEar" />
	<property name="clientclass-dir" value="${example-output}/clientclasses" />
	<path id="client.class.path">
		<pathelement path="${clientclass-dir}"/>
		<pathelement path="${java.class.path}"/>
	<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" />
	<taskdef name="clientgen" classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
	<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"/>
	<target name="all" depends="clean,build-service,deploy,client" />
	<target name="clean" depends="undeploy">
		<delete dir="${example-output}"/>
	<target name="build-service">
		<jwsc srcdir="src" destdir="${ear-dir}">
			<jws file="examples/webservices/hello_world/HelloWorldImpl.java" type="JAXWS"/>
	<target name="deploy">
		<wldeploy action="deploy" name="${ear.deployed.name}" source="${ear-dir}" user="${wls.username}" password="${wls.password}" verbose="true" adminurl="t3://${wls.hostname}:${wls.port}" targets="${wls.server.name}" />
	<target name="undeploy">
		<wldeploy action="undeploy" name="${ear.deployed.name}" failonerror="false" user="${wls.username}" password="${wls.password}" verbose="true" adminurl="t3://${wls.hostname}:${wls.port}" targets="${wls.server.name}" />
	<target name="client">
		<clientgen wsdl="http://${wls.hostname}:${wls.server.port}/HelloWorldImpl/HelloWorldService?WSDL" destDir="${clientclass-dir}" packageName="examples.webservices.hello_world.client" type="JAXWS"/>
		<javac srcdir="${clientclass-dir}" destdir="${clientclass-dir}" includes="**/*.java"/>
		<javac srcdir="src" destdir="${clientclass-dir}" includes="examples/webservices/hello_world/client/**/*.java"/>
	<target name="run">
		<java classname="examples.webservices.hello_world.client.Main" fork="true" failonerror="true">
			<classpath refid="client.class.path"/>
			<arg line="http://${wls.hostname}:${wls.port}/HelloWorldImpl/HelloWorldService" />




Open a command window and execute the setDomainEnv.cmd (Windows) or setDomainEnv.sh (UNIX) script, located in the bin subdirectory of your domain directory. The default location of WebLogic Server domains is MW_HOME/user_projects/domains/domainName

set DOMAIN_NAME=gerardnico_domain
set USERDOMAIN_HOME=C:\Oracle\Middleware\user_projects\domains\gerardnico_domain
call %USERDOMAIN_HOME%\bin\setDomainEnv.cmd
Eclipse OEPE

Add the weblogic.jar in the Antclass path by using the external configuration tools (Run > External Tools > External Tool Configuration)


One Target

Execute the jwsc Ant task:

  • at the command line by specifying the build-service target:
C:\workspace\hello_world>ant build-service
  • with Eclipse OEPE. In the outline view, select the build-service target and Run > External Tool > Run as > Ant Build
Buildfile: C:\workspace\hello_world\build.xml
     [jwsc] warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
     [jwsc] JWS: processing module /examples/webservices/hello_world/HelloWorldImpl
     [jwsc] Parsing source files
     [jwsc] Parsing source files
     [jwsc] 1 JWS files being processed for module /examples/webservices/hello_world/HelloWorldImpl
     [jwsc] JWS: C:\workspace\hello_world\src\examples\webservices\hello_world\HelloWorldImpl.java Validated.
     [jwsc] Processing 1 JAX-WS web services...
     [jwsc] warning: Annotation types without processors: [javax.xml.bind.annotation.XmlRootElement, javax.xml.bind.annotation.XmlAccessorType, javax.xml.bind.annotation.XmlType, javax.xml.bind.annotation.XmlElement]
     [jwsc] 1 warning
     [jwsc] Compiling 3 source files to C:\Users\RIXNI\AppData\Local\Temp\_gwf3vm
     [jwsc] Deleting existing module outputFile C:\workspace\hello_world\output\helloWorldEar\examples\webservices\hello_world\HelloWorldImpl.war
     [jwsc] Building jar: C:\workspace\hello_world\output\helloWorldEar\examples\webservices\hello_world\HelloWorldImpl.war
     [jwsc] Created JWS deployment outputFile: C:\workspace\hello_world\output\helloWorldEar\examples\webservices\hello_world\HelloWorldImpl.war
     [jwsc] [EarFile] Application File : C:\workspace\hello_world\output\helloWorldEar\META-INF\application.xml
[AntUtil.deleteDir] Deleting directory C:\Users\RIXNI\AppData\Local\Temp\_gwf3vm
Total time: 4 seconds

See the output/helloWorldEar directory to view the files and artifacts generated by the jwsc Ant task.


Execute the jwsc Ant task:

  • at the command line by specifying the build-service target:
C:\workspace\hello_world>ant all
  • with Eclipse OEPE: Run > External Tool > Run as > Ant Build. The default target (ie all) will run.




<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.5. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.5. -->
<definitions targetNamespace="http://hello_world.webservices.examples/" name="HelloWorldService">
			<xsd:import namespace="http://hello_world.webservices.examples/" schemaLocation="http://localhost:7003/HelloWorldImpl/HelloWorldService?xsd=1"/>
	<message name="sayHelloWorld">
		<part name="parameters" element="tns:sayHelloWorld"/>
	<message name="sayHelloWorldResponse">
		<part name="parameters" element="tns:sayHelloWorldResponse"/>
	<portType name="HelloWorldPortType">
		<operation name="sayHelloWorld">
			<input message="tns:sayHelloWorld"/>
			<output message="tns:sayHelloWorldResponse"/>
	<binding name="HelloWorldPortTypePortBinding" type="tns:HelloWorldPortType">
		<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
		<operation name="sayHelloWorld">
			<soap:operation soapAction=""/>
				<soap:body use="literal"/>
				<soap:body use="literal"/>
	<service name="HelloWorldService">
		<port name="HelloWorldPortTypePort" binding="tns:HelloWorldPortTypePortBinding">
			<soap:address location="http://localhost:7003/HelloWorldImpl/HelloWorldService"/>



taskdef class cannot be found

C:\workspace\hello_world\build.xml:5: taskdef class weblogic.wsee.tools.anttasks.JwscTask cannot be found
 using the classloader AntClassLoader[]

The jar Middleware_home/wlserver_10.3/server/lib/weblogic.jar“ is not in the AntBuildPath.

Two solutions:

  • run the setDomainEnv
  • in Eclipse OEPE, add the weblogic.jar in the AntPath by using the external configuration tools (Run > External Tools > External Tool Configuration)

Target “all”does not exist in the project

Target "all" does not exist in the project "webservices-hello_world".

When using the example of the documentation, the default action is all but the all target doesn't exit then:

  • Replace
<project name="webservices-hello_world" default="all">


<project name="webservices-hello_world" default="build-service">
  • or add a all target
<target name="all" depends="clean,build-service,deploy,client" />

Unable to contact 'myManagedServer'

[wldeploy] java.rmi.RemoteException: [Deployer:149145]Unable to contact 'myManagedServer'. Deployment is deferred until 'myManagedServer' becomes available.

Documentation / Reference

Powered by ComboStrap