Thursday, May 16, 2013

Creating a Java Enterprise Application with EE 5 and JBoss 5.1 EAP

Steps for Creating a Java Enterprise Application with EE 5 and JBoss 5.1 EAP

  1. Install Netbeans
  2. Install JBoss and configure
  3. Create the Enterprise Application
  4. Create a Session Bean
  5. Create a REST service from patterns\
  6. Clean and Build the Project
  7. Run the Server Manually
  8. Deploy the Enterprise Archive
  9. Access the Service via HTTP



Install Netbeans

Here's a link on how to innstall the Netbeans IDE in your machine.

Install JBoss and configure

You can learn about the installation of JBoss for our previous post at http://ifsinternz.blogspot.com/2013/05/installing-jboss-on-windows-environment_6.html

Create the Enterprise Application

Open the IDE and select Java EE --> Enterprise Application


Then name and configure your application by selecting your Server and Java EE Version.Also if you want an instance different from the Default one , you can also set the port and instances.





Finally Finish the setup.


Create a Session Bean

Then we will add a session Bean to keep the Business logic of the Application.


Then you can create the business logic and then we will see how the IDE will auto generate the interface for the method that we define.


Create a REST service from patterns

Now to use the EJB for the RESTful web service we will create a new RESTful Web Service from Patterns.This will just be a service providing root resources.
You can define the type of MIME you want and the output Representation.





Lets now define the EJB instance in the new REST Service we created and produce the output of it in the get HTML method for the consumer to consume.






Clean and Build the Project


In Netbeans you can very easily deploy the project with the Server and run the instance.But as a developer it is a good practice to seperate the process of deployment from the IDE.That way you can easily debug and find errors that are sometimes much more time consuming to find using the IDE.


So we will use the clean and Build at the IDE to Generate the .ear file and manually deploy it in the Server.


Deploy the Enterprise Archive

To deploy the enterprise application to JBoss you can copy the .ear from the netbeans project ( It will be at the dist folder of the project) and paste it directly in the deploy folder of the JBoss Installation instance.
COPY:





PASTE:
















Run the Server Manually

To run the server manually you can just use the run command at the bin directory.But if you use an instance other than the default instance of the server you have to tell it to the server by using the run -c <your_instance_name>  command.  
 



Access the Service via HTTP




extra : Class cast error
Library mismatch

No comments:

Post a Comment