Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
/ sample.ejb Public archive

A sample that demonstrates injection of an EJB into a servlet and provides an application consisting of a servlet and stateless session bean.

License

Notifications You must be signed in to change notification settings

WASdev/sample.ejb

Repository files navigation

Enterprise Java Beans (EJB) Sample Build Status

This sample demonstrates injection of an EJB into a servlet. The application consists of a servlet and stateless session bean. The servlet uses annotations to inject the stateless session bean, and then performs a call on the hello method of the bean.

This sample can be installed onto runtime versions 8.5.5.0 and later.

Maven

The Liberty Maven plug-in and WebSphere Developer Tools support creating loose applications. This example creates a loose EAR application when building using Maven. After running the full build, you will see the application installed as sample.ejb/ejb-ear/target/liberty/wlp/usr/servers/ejbServer/apps/ejb-ear.ear.xml.

Using Eclipse with Maven

  1. Clone this project and import into Eclipse as an 'Existing Maven Project'.
  2. Right-click the project and select Run As > Maven Clean.
  3. Right-click the project and select Run As > Maven Install.
  4. Right-click the project and select Run As -> Run on Server.
  5. You should see the following in the console: Application EJBSample started in XX.XX seconds.

Using the command-line with Maven

This project can be built with Apache Maven. The project uses the Liberty Maven Plug-in to automatically download and install the Liberty Java EE 7 Full Platform 7 runtime from Maven Central. The Liberty Maven Plug-in is also used to create, configure, and run the application on the Liberty server.

Use the following steps to run the application with Maven:

  1. Execute the full Maven build. The Liberty Maven Plug-in will download and install the Liberty server in the ejb-ear project. It will also run all tests.

    $ mvn clean install
  2. To run the server in the ejb-ear subproject:

    $ mvn --projects ejb-ear liberty:run-server

    The --projects and -pl are equivalent options.

In your browser, enter the URL for the application: http://localhost:9080/ejb-war/ejbservlet/ In your browser, you should see the message "Hello EJB World".

Gradle

This project can also be built with Gradle. The project uses the Liberty Gradle Plug-in to automatically download and install the Liberty Java EE 7 Full Platform runtime from Maven Central. The Liberty Gradle Plug-in is also used to create, configure, and run the application on the Liberty server.

The Liberty Gradle Plug-in supports creating loose application configuration for war tasks, but it does not yet support loose enterprise applications. This example installs the EAR file when building using Gradle. After running the full build, you will see the application installed as sample.ejb/ejb-ear/build/wlp/usr/servers/ejbServer/apps/ejb-ear.ear.

Using Eclipse with Gradle

  1. Go to Help > Eclipse Marketplace > Install Buildship Gradle Integration 2.0
  2. Clone this project and import into Eclipse as an 'Existing Gradle Project'.
  3. Go to Window > Show View > Other > Gradle Executions & Gradle Tasks
  4. Go to Gradle Tasks view and run clean in build folder, then build in build folder, then libertyStart in liberty folder.
  5. You should see the following in the console: Application EJBSample started in XX.XX seconds.

Using the command-line with Gradle

Use the following steps to build and run the application with Gradle from the root project:

  1. Execute the full Gradle build. The Liberty Gradle Plug-in will download and install the Liberty server in the ejb-ear project. It will also run all tests.

    $ ./gradlew clean build
  2. To start the server with the EJB sample application run:

    $ ./gradlew libertyStart

    Alternatively, execute the run command:

    $ ./gradlew libertyRun --no-daemon
  3. To stop the server, run:

    $ ./gradlew libertyStop

In your browser, enter the URL for the application: http://localhost:9080/ejb-war/ejbservlet/ You should see the message "Hello EJB World".

Notice

© Copyright IBM Corporation 2017.

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A sample that demonstrates injection of an EJB into a servlet and provides an application consisting of a servlet and stateless session bean.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages