Jar file for javax.ejb.sessionbean
To explicitly specify the enterprise bean modules initialized by the embedded container, set the EJBContainer. The modules may be located either in the virtual machine classpath in which the embedded container and client code run, or alternately outside the virtual machine classpath. To specify modules in the virtual machine classpath, set EJBContainer. The embedded container searches the virtual machine classpath for enterprise bean modules matching the specified names:.
To specify enterprise bean modules outside the virtual machine classpath, set EJBContainer. File object or an array of File objects. Use an instance of EJBContainer to retrieve a javax. Context object. Call the EJBContainer. For example, to obtain a reference to MySessionBean , a local session bean with a no-interface view, use the following code:. From the client, call the close method of the instance of EJBContainer.
While clients are not required to shut down EJBContainer instances, doing so frees resources consumed by the embedded container. This is particularly important when the virtual machine under which the client application is running has a longer lifetime than the client application.
It is now time to put all this theory into practice. In this section, we're going to develop our first session bean in an example that's on par with the traditional "Hello World!
First, we'll walk through the bean-creation code in a good bit of detail, reinforcing concepts we just covered and introducing new ones. Then we'll explain how to compile the example. Finally, we'll deploy the example in JBoss. Since this is the first EJB example, we're going to walk through the code now and then run it later.
There are three Java source files for this example: SimpleSession. Listing 2 shows the code for the actual bean implementation, SimpleSessionBean.
After you've created and organized the sample session bean files as just described, follow these steps to compile the application:. These libraries contain all of the EJB functionality needed to make your code interact with the application server, so it is extremely important that you get this step right.
At the command line, type the following this should all be on one line :. Within the SimpleSessionApp directory where the client and beans directories are located, execute the following commands from the command prompt:.
The —d option tells the Java compiler to place the class files in subdirectories matching their package structure, subordinate to the given directory. In this case, the given directory is the current directory, signified by the period.
As a result, the Java class files should end up in the same directories as the source files. Now we need to start the JBoss Server. Once the JBoss Server is up and running, you can deploy your class files. In order to deploy your class files, you need to package your different application components together in a compressed jar file. Make the extension of this file. To create the application EJB3 file, open a command prompt in the same directory that SimpleSessionApp resides in and type in the following command:.
JBoss will automatically detect and deploy your code for you. The directory structure should now have the files shown in Figure 5. Next, with SimpleSessionApp as the current directory, execute the following command from the command prompt remember that this is all one line :.
When you run the SimpleSession client program, it will produce the following output:. We have three Java source files to walk through here. We'll start with the client and work our way back up to the session bean interface and class. This mapped name is often a global JNDI name, but may be a name of any form.
Application servers are not required to support any particular form or type of mapped name, nor the ability to use mapped names.
The mapped name is product-dependent and often installation-dependent. No use of a mapped name is portable. All Rights Reserved. Use is subject to license terms. Skip navigation links. The beanName element references the value of the name element of the Stateful or Stateless annotation, whether defaulted or explicit.
The product specific name of the EJB component to which this ejb reference should be mapped.
0コメント