EJB-JPA-JBOSS

Getting Started with EJB3-JPA

Create  Simple Project EJB  (Entity, Session,Client Java, Web Service) on JBOSS Server As 7.1 with Eclipse (Luna):

Prerequisites

Before performing this project, you need to meet the following prerequisites:

 Eclipse (Luna) Java EE IDE for Web Developers :

JBOSS 7.1.1 installation on Windows 7 :

Configuration JBOSS in Eclispe :

Add new Server Runtime Environement

window –> Preferences –> select Server –> Runtime Environment —> add

2Create new server :

3

Start the server : Jboss server was not working. On server.log it was saying port 9990 was used. Here is the output;

5

To fix this, go to services.msc and find NVIDIA Network Service (NvNetworkService) and stop it.

Restart the server.

8

When show Administration Console we need to creat users to be acces the console admin

10

use command add-user.bat : create username and password

11

To be access in the console admin put your username and your password.

Adding a MySQL datasource to JBoss :

The connector can be downloaded from: http://dev.mysql.com/downloads/connector/j/.

Copy the driver jar to the new directory and move to that directory: jboss-as-7.1.1.Final/modules/com/mysql/main

The module.xml contains basically the module name, the resources used and its dependencies.

16

Now the module has been created :

17

We need to make a reference to it from the main application server configuration file : /standalone/configuration/standalone.xml.

The module name, com.mysql, should match the directory structure for the module

Find the ‘drivers’ element and add a new driver to it:

15

Start the Jboss Server

Now try running the application server. Hopefully, amongst the application server’s console output you should see the following  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool — 27) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)

To be sure, the directory structure for the module added new file mysql-connector-java-5.1.21.jar.index.

The JDBC driver is now installed and set up as a core module, and is available to be referenced by application datasources.

Add the Datasource in Administration Console

Profile –> connector –> DataSources

21

 

Select the JBDC Driver : mysql

21

put the property attributes name and JNDI Name

19

Configuration the connection: you should create a database in our tutorial named mydb.

22

Test the JDBC connection : we must to enable the datasource

 

23

You can see the configuration data source in the file standlone.xml

25

 Create Project EJB:

7

9

Create class Entity Product

3133

Create the file persistence.xml

34

Run the project on the server

35

The application server’s console output you should see the following :

36

The project was deployed and the tabe Product are created !!!

37

Create the interface IProductRemote:

28

Create the interface IProductLocal:

40

Create class EJBProductImpl implements IProductLocal and IProductRemote:

38 39

The application server’s console output you should see the following

41

Create new Project Java :

50

Create class ClientEJB to test the Project

51

55
In order to run this application you need to place a file named jboss-ejb-client.properties in the client classpath

56Last thing, if you are running your client from Eclipse, you need to place an additional library named jboss-client.jar in the client CLASSPATH. (The library is located into jboss-as-7.1.1.Final/bin/client folder):

60

You need also to add the project EJBProject.

61

As you can see from the following picture :

59

Run the class as Java Application, in the console output you should see the following

57

As you can see the client can add new Product !!!

58

 

Web Service

Create class Product Service

70Run the project as Full Publish :

73The application server’s console output you should see the following :

72

http://localhost:8080/EJBProject/ProductService?wsdl

71

you can download the project by following this link https://github.com/AMhadhbi/EJBProject

I hope it will be useful for you all.

Enjoy it 🙂

Leave a comment