Playing around with EJB3.0 for a while, I decided to try the special webservice annotations set of EJB3.0 for deploying an EJB as a webservice.Looking at the documentation, I discovered that that this feature is based on the new Java XML webservice API called JAX-WS (JSR-224), which is in real JAX-RPC 2.0. I decided to build a EJB3.0 with special webservice methods in JDeveloper and deploy it on the Glassfish application server. Next, I developed a client for the webservice in Netbeans 5.0 using JAX-WS. I could have used JDeveloper for building the client, but I used Netbeans 5.0 for just trying a different IDE then the one I’m daily using
.
I chose JDeveloper 10.1.3 for developing the EJB3.0 webservice, because it has, as one of the few IDEs , build-in support for EJB3.0 development. The code below shows the stateless session bean with a single webservice method that returns a message.
@Stateless
@WebService(serviceName = "MyFirstEJB3Service")
public class WebserviceEJBBean implements WebserviceEJB {
public WebserviceEJBBean() {
}
@WebMethod(operationName="HelloWorld")
public String getHelloMessage(String s) {
return "Hello " + s + "\n" +"This is my first EJB3.0 webservice developed in JDeveloper and deployed on the glassfish platform";
}
}
After you have generated a jar file for your EJB module, you login into the administration console of your Glassfish installation and deploy the jar file as an EJB module in the console (Applications -> EJB modules). After successfully deployed the module, you can test your webservice in the console (Webservices -> WebserviceEJBBean )
Ok, now we have implemented and deployed an EJB3.0 webservice on the Glassfish application server. It’s now time to make a client that consumes the webservice. Start your Netbeans 5.0 installation and make a new basic application project. Now you have to download the JAX-WS API binaries to you local drive and add them a s a library to your project. Now we have to generate artifacts to make the actual webservice call. JAX-WS contains a tool, called wsimport, to generate artifacts from a given WSDL file. You can integrate this tool as an ANT-task in your build file by inserting the following code in your project build file:
<!-- Overrides -pre-compile target
java artifacts that will created and compiled to build/classes directory. -->
<target name="-pre-compile">
<mkdir dir="build/classes"/>
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath path="${javac.classpath}"/>
</taskdef>
<echo>running wsimport</echo>
<wsimport
debug="true"
keep="true"
destdir="build/classes"
package="wsimport.generated.myfirstejbws"
wsdl="http://localhost:8080/MyFirstEJB3Service/WebserviceEJBBean?WSDL"/>
</target>
Finally, add the following code to the main method of the application’s main class and run the application to see the message returned by the webservice.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Response from the webservice: "+"\n"+Main.testService());
}
public static String testService(){
//Use the generared artifacts to make the webservice invocation.
MyFirstEJB3Service service = new MyFirstEJB3Service();
WebserviceEJBBean proxy = service.getWebserviceEJBBeanPort();
return proxy.helloWorld("Tom Hofte");
}
I think with JAX-WS developing webservices and building clients for them becomes really easy by using annotation and the supplied tools like wsimport. Sun has done a great job with this new standard XML webservice API!

March 28th, 2006 at 18:33:18
This is all much simpler with NetBeans 5.5, including writing the EJB part
March 28th, 2006 at 19:16:18
Does NetBeans 5.5 have build-in support for EJB3.0? Then I will start to look at it..
April 4th, 2006 at 11:15:48
Yes it does, including support for EJB3 persistence.
April 11th, 2006 at 19:47:05
I just tried NetBeans 5.5 and it’s using wscompile for generating a client, not wsimport. i.e. it’s still doing it the old way.
April 11th, 2006 at 19:54:19
Is it using the new version of jax-ws? Try to add the jax-ws libs to your project
April 11th, 2006 at 20:50:09
Did you get it to work with NetBeans? What’s the name of the jar file that I need to add? Are they bundled with NetBeans?
April 11th, 2006 at 21:12:51
I have downloaded it from the java.net: https://jax-ws.dev.java.net/
and add it as a library to my project. You’ll all the libs in the directory to your project. Note that I have done this in version 5.0 and not in 5.5. But I can imagine that it will work the same for 5.5
success
April 12th, 2006 at 00:01:39
Thanks for the info. I wonder if the RI can be used with Tomcat in standalone mode? Or, do you need Sun’s app server? The user guide says you need a “JAX-WS 2.0 SI enabled servlet container.”
So, NetBeans was smart enough to use JAX-WS 2.0 just by seeing the jar files there? Or, did you have to mess around with Ant scripts?
April 12th, 2006 at 09:16:06
The server you use to deploy a JAX-ws webservice, should be J2EE 1.5 compliant. This is because jax-ws havily depends on the use of annotations, an feature introduced from JEE 1.5
July 13th, 2006 at 23:11:50
Am I Tied to Oracle jax-rpc-client libraries when using oc4j ?
I ran in to a problem with jdevelopers embedded OC4J container when using web service libraries such as wsdl4j, saaj, jax-rpc.
With the code that I am currently writing, for example I used wsdl4j from Axis:
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader reader = wsdlFactory.newWSDLReader();
As this code runs normal in the jvm, it didn’t work any more ones I had deployed to oc4j and ran it from a servlet.
When I started the debugger, I noticed that the ‘reader’ variable in the code example above, was of type oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl instead of type javax.wsdl.xml.WSDLReader.
Apparently oc4j’s class-loader can’t resolve the wsdl4j.jar and uses the standard webservice jar files that are contained in the Oracle JAX-RPC CLIENT library that come with the jdeveloper installation. If I am not mistaken these are located at …\jdev1013\webservices\lib\ .
I also notices that in this lib directory oracle contains jar files for saaj, jax-rpc ect.
Does this mean you are tied down to using the oracle implementation’s of these components, or is there a way to use libraries of your chosing ?
If not I have a huge problem, either I refactor my code to work with the oracle libraries or I abandon jdeveloper completely.
Without being able to deploy my own jar files to oc4j, jdeveloper is of no use to me.. unfortunately because until now I found it a great tool.
July 14th, 2006 at 08:09:23
I do not think so..
Have you tried to pack your application as a ear file, containing the standard Java JAX-RPC libs, to a stand-alone OC4J container.
What you also could try is to remove the Oracle JAX-RPC libraries from your project properties and add the specific Java JAX-RPC..
If it still not work after trying the suggestions above, you can also post on the JDeveloper forum on OTN…
July 14th, 2006 at 16:25:51
thanks for the reply, but I am talking about the embedded oc4j. which makes a great difference in that sense that I cant test my code after I write it. For now I am deploying it to tomcat with the consequence that I have to reboot tomcat each time.
As for your suggestion, I did use the oracle jax-rpc client libraries in my project, I only added my own wsdl4j and jax-rpc-api saaj jars. For whatever reason in the embedded oc4j, the container still loads the oracle ws libraries.
You would think that this is a very common thing to do, however the boys at Oracle have no clue which I find rather surpring since this is nothing abnormal. Anyway, steven davelaar and mike de groot didnt know, perhaps I should try one league up and email Steve muench. Thanks for the effort anyway..
July 14th, 2006 at 17:26:49
oops.. I meant to say I DIDNT use the jax-rpc client libraries in my project.
July 17th, 2006 at 15:39:29
In case anyone is interested in the solution to the problem mentioned above :
http://forums.oracle.com/forums/thread.jspa?messageID=1379129�
January 18th, 2008 at 02:13:46
I realize this is an old blog, but I have a similar situation maybe one of you can help me with?
We have a large PowerBuilder/Oracle application. The db consists of over 500 tables and the client consists of several thousand PB components. A user creates “transactions” which contain a series of “sub-transactions” within. Most of the data is collected and stored locally in the client in a series of datastores. When the “finalize” happens, the records are validated and sent to the database.
We are in the process of moving each of the subtransactions (currently in the PB client) into subPROCESSES on a java project. We are using the JAX-WS framework to develop the web services in Netbeans. For writing data back to the database, we are using the Java Persistence API to function outside of an EJB container but will shortly be migrating to the Glassfish application server to use several of the EJB container frameworks including the EntityManager.
I’m trying to figure out a deployment methodology that will provide minimal impact on existing applications and maximal re-use of code (i.e. loosely coupled).
We will want to use the persistence code, the data access code, and a few other pieces of code in several applications.
Is it common practice to use the same libraries over and over in several applications?
What are some common deployment models?
How can we determine where our breaks between applications should be so that we can loosely couple code in a sane manner?
Any suggestions would be so helpful and appreciated!
Thanks!