About software development for the enterprise. Focus on Java EE and more general Java platforms.
You'll read a lot about Conferences, Java User Groups, Java EE, Integration, AS7, WildFly, EAP and other technologies that hit my road.

Wednesday, January 20, 2010

GlassFish v3, CDI, Maven, Eclipse

07:51 Wednesday, January 20, 2010 Posted by Markus Eisele
, , , ,
I am disaffected with NetBeans. It looks fancy, but I still can't get back the love I had using the 3.x version :) Seems as if I am converted to an Eclipse lover.
This was the point where I started to try getting CDI examples to work with GlassFish v3, CDI/Weld, Maven and Eclipse.
For those of you, haven't made it. Here is the how-to (I am using versions with the numbers in brackets):

1) Get:
- Maven (2.2.1)
- Eclipse (3.6M2)
- GlassFish (v3 build 74.2)

2) Create a maven project using:

mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=cditests -DarchetypeArtifactId=maven-archetype-webapp


3) Add a my-webapp\src\main\java folder to it
4) Add the following dependencies to the my-webapp\pom.xml

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>provided</scope>
<version>1</version>
</dependency>

<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
<version>1.0</version>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>


5) Add an empty file named beans.xml to my-webapp\src\main\webapp\WEB-INF
6) run mvn eclipse:eclipse for making this an eclipse based project
7) add your code
8) run mvn clean install (compile / package)
9) deploy it to your GlassFish domain
10) think about enhancing this with JSF 2.0 ;)