Wednesday, December 12, 2012

Enterprise Application Integration - Tutorial

Installing and Configuring JBoss AS and JBoss Tools

Contents

  1. Installing the latest JDK
  2. Installing JBoss AS 6
  3. Installing Eclipse 3.6.2
  4. Installing JBoss Tools 3.2

Installing the latest JDK

  1. Make sure that the latest version of the Java Development Kit (JDK 6 Update 24 or later) is installed on your computer. If the JDK is properly installed on your computer, you can jump to step 4 of this section, otherwise continue with the next step.
  2. Go to http://www.oracle.com/technetwork/java/javase/downloads/index.html and follow the instructions on Oracle's website to download the latest version of the JDK (Java SE 6 Update 24 or later) for the operating system of your computer.
  3. Install the JDK to a directory on your computer, e.g. C:\Java\jdk1.6.0_24.
  4. Create an environment variable called JAVA_HOME that points to the JDK installation directory, for example C:\Java\jdk1.6.0_24.

Installing JBoss AS 6

  1. Get the latest stable version of the JBoss Application Server (6.0.0.Final) from http://sourceforge.net/projects/jboss/files/JBoss/JBoss-6.0.0.Final/ (jboss-as-distribution-6.0.0.Final.zip).
  2. Extract the zip archive to a directory on your computer, e.g. C:\EAI. The path must not contain any spaces. A new directory, e.g. C:\EAI\jboss-6.0.0.Final, containing the JBoss AS files will be created.
  3. Use the script <JBoss directory>\bin\run.bat to start the JBoss server and check the installation. After startup, you should be able to access the web server at http://localhost:8080.
  4. In order to stop the server, press CTRL-C in the console window that was opened during step 3.

Installing Eclipse 3.6.2

  1. Download the Eclipse IDE for Java EE Developers for your operating system (version 3.6.2, Helios SR2) from http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/heliossr2.
  2. Extract the downloaded archive, e.g. eclipse-jee-helios-SR2-win32.zip, to a directory on your computer, e.g. C:\EAI. This will create a sub directory, like C:\EAI\eclipse.
  3. Start Eclipse. The eclipse.exe is located in the installation directory. Wait for the "Workspace Launcher" window to pop up and select a workspace directory, for example C:\EAI\projects. This path must not contain any spaces either. The workspace directory is where all your projects will be stored. You may check the "Use this as the default and do not ask again" box to avoid this dialog from appearing on the next start. Click "OK" to close the dialog and get to the workbench window.

Installing JBoss Tools 3.2 for Eclipse

  1. Select "Help->Eclipse Marketplace..." from the Eclipse menu bar. Choose "Eclipse Marketplace" if prompted for a marketplace catalog.
  2. Search for "JBoss Tools" and install JBoss Tools (Helios), version 3.2.x.
  3. Wait until "Calculating requirements..." has finished and make sure that all features are checked, then click "Next".
  4. Accept the license agreements and click "Finish".
  5. When the download is complete, a security warning regarding "Unsigned content" will appear. Accept with "OK" to begin with the installation.
  6. When prompted to do so, "Restart Now".
  7. After closing the "Welcome" window you will see the "Java EE" perspective. The selected perspective is indicated in the upper right corner as shown in the following figure:

    If the Java EE button is not visible you can change to the Java EE perspective via "Window->Open Perspective->Other..." . In the "Open Perspective" dialog double click the Java EE entry.
  8. Activate the "Servers" view tab in the lower right of the window. Right-click the empty area and select "New->Server" as shown in this screenshot:

  9. In the "New Server" window select "JBoss AS 6.0" (from the JBoss Community category) as server type and click "Next".

    Set the "Home Directory" entry to the installation directory of the JBoss AS, e.g. C:\EAI\jboss-6.0.0.Final, and click "Finish".
  10. In the "Servers" view select the newly created server and click the green start button.

    A new "Console" view will open showing the startup logs of the JBoss AS.
Congratulations, you have successfully installed JBoss AS and JBoss Tools!
Continue with the setup of your first Java EE project.

Please send questions and comments regarding this tutorial to Henning Heitkötter.

How To Set Environment Variables

  • Windows XP: Open the Control Panel (Systemsteuerung) from the Start Menu, switch to Classic View (Klassische Ansicht) if necessary, open the System Control Panel applet (System), select the Advanced tab (Erweitert), and click on the Environment Variables button (Umgebungsvariablen).
  • Windows 7: Control Panel (Systemsteuerung) - System - choose Advanced System Settings (Erweiterte Systemeinstellungen) on the left - Advanced tab (Erweitert) - Environment Variables button (Umgebungsvariablen)
Link Source: http://www.wi.uni-muenster.de/pi/lehre/ss11/EAI/tutorials/tutorial_jboss_setup.html

Enterprise Application Integration - Tutorial


Creating Java EE projects with JBoss Tools

Contents

  1. Preconditions
  2. Importing the Example Application into Eclipse
  3. Creating an Enterprise Application from scratch

Preconditions

  • Make sure JBoss AS and Eclipse with JBoss Tools Plug-in are properly installed and configured (tutorial).
  • Start Eclipse with JBoss Tools Plug-in and make sure the Java EE perspective is opened.
  • Make sure that a JBoss 6.0 Runtime Server is configured in Eclipse as outlined in the first tutorial.

Importing the Example Application into Eclipse

This tutorial will show how to import a Java EE application using the example of a library application. It allows you to quickly get started with Eclipse, Java EE and JBoss Tools. The next section, "Creating an Enterprise Application from scratch", will show how you can create your own Java EE projects.
  1. Download the library application source files to a temporary folder.
  2. Select "File->Import..." from the Eclipse menu bar.
  3. Choose "General > Existing Projects into Workspace" and click next.
  4. Choose "Select archive file" and browse to the archive from step 1.
  5. Four projects called Library, Library-EJB, Library-Persistence and Library-Web should appear under "Projects". Make sure all four are selected and "Finish".
  6. The project explorer should now contain the four projects. Eclipse will automatically validate and build the projects.
  7. In the "Servers" tab, right-click on your JBoss 6.0 server and select "Add and Remove...".
  8. Select the library application and click "Add >", then "Finish.
  9. Start the server and wait until the application has been deployed.
  10. The Library web application is accessible under http://localhost:8080/Library-Web/.

Creating an Enterprise Application from scratch

The following instructions show how to create an enterprise application from scratch, without importing existing projects. It may be helpful when you start developing your own application, for example during the practical course.
An enterprise application consists of several projects. In the following, the application is made up of four projects:
  1. Enterprise Application Project: a container project that packages the other projects into an .ear file for deployment purposes.
  2. JPA Project: the data model of your application, contains mostly Entities.
  3. EJB Project: the business logic of your application, contains mostly Session Beans.
  4. Web Project: the web presentation layer of your application, implemented using JSF technology, contains web pages and Java classes as backing beans.
This tutorial uses "Test" and variations thereof as project names. Of course, you are free to choose your own names.

New Enterprise Application Project

  1. Select "File->New->Enterprise Application Project" from the menu bar.
  2. In the "New EAR Application Project" dialog, enter "Test"as project name, makesure that JBoss 6.0 is the target runtime and click "Finish".

New JPA Project

  1. Select "File->New->JPA Project" from the menu bar.
  2. In the "New JPA Project" dialog, enter "Test-Persistence" as project name. Again, the target runtime should be JBoss 6.0. "Minimal JPA 2.0 Configuration" should be selected as "Configuration".
  3. As we want this project to be part of the enterprise application, we select "Add project to an EAR" and choose our Test project from the "EAR Project Name" menu.
  4. Click "Finish". (Do not switch to the JPA perspective if asked to do so.)
  5. Open the file "persistence.xml" (under "JPA Content" or under src/META-INF/) and switch to the "Source" tab. Modify the node persistence-unit to match the following snippet:
    <persistence-unit name="Test-Persistence">
      <jta-data-source>java:/DefaultDS</jta-data-source>
      <properties>
        <property name="hibernate.hbm2ddl.auto"
          value="create-drop"/>
      </properties>
    </persistence-unit>
    This defines the data source to use ("java:/DefaultDS" is the JNDI address of the built-in HSQL database of  JBoss AS) and ensures that you always start with a fresh database after deployment. When you've reached a stable data schema, you can use "validate" or "update" instead of "create-drop".
  6. To create your first Entity, right-click on the project, select "New->Entity" and follow the wizard.

New EJB Project

  1. Select "File->New->EJB Project" from the menu bar.
  2. In the "New EJB Project" dialog, enter "Test-EJB"as project name. The "EJB module version" should be set to 3.1.
  3. As we want this project to be part of the enterprise application, we select "Add project to an EAR" and choose our Test project from the "EAR Project Name" menu.
  4. After clicking "Next" twice we disable the "Create an EJB Client Jar..." check box. For the moment we do not need a separate EJB client jar file.
  5. A click on "Finish" will create a new library-ejb project.
  6. To create a Session Bean, right-click on the project, select "New->Session Bean (EJB 3.x)" and follow the wizard.

New Web Project

  1. Select "File->New->Dynamic Web Project" from the menu bar.
  2. In the "New Dynamic Web Project" dialog, enter "Test-Web"as project name. The "Dynamic web module version" should be set to 3.0.
  3. Under "Configuration", select "JavaServer Faces v2.0 Project" from the drop-down menu.
  4. As we want this project to be part of the enterprise application, we select "Add project to an EAR" and choose our Test project from the "EAR Project Name" menu.
  5. A click on "Finish" will create a new library-web project.
  6. XHTML Pages with Facelets markup go into the WebContent folder ("New->Other..."). Backing beans should be created as Java classes under JavaResources/src.
Please refer to steps 7-9 of the section "Importing the Example Application into Eclipse" in order to learn how to deploy your project.