Skip navigation
2010

With JBoss Tools 3.2 Beta 2 it is simple to start using CDI (Context Dependency Injection).

 

All you need is the following:

 

 

Here it is as a video walk through:

 

 

...and here are the steps in Screenshot form:

 

Step 1: Install/Configure the Server runtime

The simplest way to setup JBoss runtimes is to use the "JBoss Runtimes" preference page which are available

via the Preferences or by simply pressing Ctrl+3 and type in "JBoss runtimes".

 

hellocdi_ctrl3runtimes.png

When pressing enter you should see the following Preferences page:

 

hellocdi_preferencepageruntimes.png

Click the "Search..." button and point it to a directory with your JBoss runtimes; in this case I got a few.

 

hellocdi_selectruntimefolder.png

When you have selected the directory JBoss Tools will scan for runtimes it knows about and show

you what it found:

 

hellocdi_foundruntimes.png

In this dialog you can then remove the checkmarks for runtimes you do not want configured or simply press OK and JBoss Tools will make all selected runtimes available from within the IDE.

 

For the Server parts it is now availabe in the server view:

 

cdihelloworld_servers.png

From here you can start the server (in this case JBoss 6) by clicking the Debug or Run icon. If you start via Debug icon the server will wait at any breakpoints you have set in your code and allow you to inspect the current state.

 

In any case when the server starts up it sends the output of the console to the Console View:

 

helloworld_cdi_console.png

Step 2: Create the Project

Now use the File > New > Dynamic Web Project or simply press Ctrl+N and find the "Dynamic Web Project" wizard

 

dynamic_web_project.png

On the Wizard page, type in a project name (i.e. "cditest") and Click the "Modify" button under Configuration.

 

webprojectwizard.png

The Modify Configuration is where you can enable/disable what Eclipse calls project facets.

In this case we simply want to enable the Context Dependency Injection facet.

 

cdifacet.png

Now Click Ok and press Finish on the Wizard and a basic WAR project will be created for you.

cdiproject.png

Step 3: Create the code

The code we will create are the minimal for printing out Hello World via a servlet.

 

We will need to add the following files:

 

  • WebContent/WEB-INF/beans.xml to enable CDI fully for the project (in next revision of JBoss Tools this file will be created for you)
  • src/org/cditest/HelloWorld.java the bean for giving the "Hello World" greeting.
  • src/org/cditest/HelloServlet.java the servlet for rendering the greeting in its response method.

 

To create the bean.xml simply use Ctrl+N and type in "XML File" and choose the WebContent/WEB-INF folder and give it the name: beans.xml

 

beans.png

The default file is empty, but we need to add the following content to make it work:

 

<beans/>

 

that will suffice for this blog; remember the beans.xml file is simply just

a marker file to inform the CDI container that the War archive should be scanned for beans.

 

Next on comes the HelloWorld and Servlet class - for this I will just paste the simplest code

which you can paste into two .java files or use Eclipse's excellent wizards for it. If you want to see the full steps for this you can watch the video above.

 

HelloWorld.java:

 

package org.cditest;

public class HelloWorld {
    public String getGreeting() {
        return "Hello World!";
    }
}

 

HelloServlet.java:

 

package org.cditest;

import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet("/HelloServlet")
public class HelloServlet extends HttpServlet {
    @Inject private HelloWorld hello;
       
    public HelloServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
        throws ServletException, IOException {
        response.getOutputStream().println("<html><h1>" + hello.getGreeting() + "</h1></html>");
    }
}

 

If you look at the code of the HelloServlet you can see it simply a class with a @WebServlet annotation to specify the context/url name, an @Inject annotated field called Hello and a doGet() method which prints out the value of hello.getGreeting().

 

In short, the simplest example of @Inject annotation on a servlet.

 

Step 4: Run the Servlet


From within Eclipse you can use the Run As... or Debug As... toolbar menu to run what is the current selection and the tools will try and guess what kind of "Run" that means. i.e. for an XHTML page named home.xhtml it might be to open up a browser at http://localhost:8080/home.seam or in this case for a Servlet to open up the browser at the @WebServlet specified location relative to the deployment name, i.e. http://localhost:8080/cditest/HelloServlet.

 

runonserver.png

For new projects like this example Eclipse will ask you what Server you wish to run on:

 

selectserver.png

In this case I got several servers available, so I will choose the JBoss 6 server and

choose "Always use this server when running this project" so I will not have to answer

this question again on future Run's.

 

When the server is selected JBoss Tools will deploy the application and show the relevant page

in a browser:

 

browserhelloworld.png

 

Step 5: Have fun!

That is it - and there is of course more functionallity in the CDI tooling such as validations, quick fixes and code completions but I thought it would be good to just show the simplest application imaginable.

 

But with the steps described above you now know how to setup any JBoss runtime, create any kind of project and enable the Eclipse facets you want on them.

 

If you want to see how easy it is to debug your applications then watch the video above, it has a little more details.

 

Hope you enjoyed it

 

p.s. the exact same steps can be used to run against Glassfish or other CDI enabled servers that has Eclipse WTP server adapters.

http://community.jboss.org/servlet/JiveServlet/downloadImage/38-2030-10503/449-54/earlyaccess.png

In addition to releasing JBoss Tools 3.2 Beta 2 we've also released the second Beta of JBoss Developer Studio 4 to our early access site which incorporates the updated plugins from the JBoss Tools release.

 

You can download the full Eclipse based IDE from the early access site  for free,  and if you want to have the no-fuzz-single-click-install  experience  with JBoss Enterprise Application platform bundled you just  need to go  and sign up for the early access program here.

 

Have fun!

Here is a freshly cut Beta 2 of JBoss Tools 3.2 for you to enjoy this season.

 

http://in.relation.to/service/File/10824

3.2.0.Beta2

[Download] [Update Site] [What's New]  [Movies]  [Documentation] [Forums] [JIRA] [Twitter]

 

The end is near!

This is the last beta planned before we do a planned CR1 and then Final next month.

 

If you are on Eclipse 3.6 (Helios) we definitely recommend you to upgrade to this version. It has never been better.

 

We are hungry for feedback!

A few last improvements

For this last beta we've squeezed in some improvements within the almost 500 issues fixed in this round.

Simplified Download and installation

The simplest way to install the most commonly downloaded JBoss Tools 3.2.x plugins is now to use Eclipse Marketplace.

Eclipse Marketplace is available from the Help > Eclipse Marketplace menu in Eclipse.

 

When you install JBoss Tools via Eclipse Marketplace you get the "Web 2.0" plugins in one click - if you want additional or the complete plugin set you can use the complete Update Site.

 

Finally we also provide a zipped version of the Update sites from our Download page, which this time is also reduced to just the most popular download options instead of listing all 60+ sub-components individually.

 

Let us know what you think about this simplified installation!

More Platforms

You can now install all of JBoss Tools on any Eclipse compatible OS and in particular Windows and OS X 64-bit. Previously we limited the installation to those where the Visual Page Editor can run which unfortunately excluded some OS's. That restriction has now been lifted which means all can now get advantage of the complete tooling, except for the visual part of the editor which still only will be available on platforms were there exists working XULRunner/SWT bindings.

Cloud & Remote deployment

There have been done a lot in the area of the JBoss Server adapter Remote System support and for the Delta Cloud tooling but most importantly is that the SteamCannon team is now hosting a DeltaCloud server you can try and use together with JBoss Tools without having to setup your own DeltaCloud server.

 

The url for this is http://try.steamcannon.org/deltacloud/ and can be used as the URL for a Cloud Connection in the Cloud Wizard in JBoss Tools.

 

Note: Please beaware that this URL is still driven by experimental code and can at any time stop working - so try it while you can

Performance!

Beta 2 delivers 10 X performance improvements over M2 in the HTML and JSF validation - making this release the fastest ever!

JBoss 6 and CDI

The latest JBoss 6 release provides a full-fledged CDI environment and JBoss Tools now provide full set of code completion, validation, refactoring and quick fixes for CDI. If you are into trying out CDI using JBoss Tools with JBoss 6 gets you started very easily.

...and more!

Hibernate, Seam, Drools, BPEL, ESB, GWT and Modeshape also received a good set of fixes and improvements - you can see more about these in the What's New

 

Now go Get It and Have Fun!

Filter Blog

By date:
By tag: