steinberg nuendo 4 price buy mudbox 2009 autocad 2010 pricing buy 3ds max 2010 cheap download autodesk autocad 2009 ms access 2007 download buy ms office for mac windows 7 home premium oem 32 bit soundbooth cs4 download buy windows xp license online cheap adobe fireworks microsoft streets and trips 2010 best buy download acrobat 9 microsoft office 2010 beta download buy windows 2008 datacenter cheap windows 7 ultimate download download corel draw 10 adobe cs4 design premium mac full version windows 2003 enterprise licensing windows 7 64 bit oem price lightroom price buy autodesk inventor 2009 after effects for mac trial download cubase sx3 full version cheap illustrator cs3 adobe premiere full download microsoft office onenote 2003 download buy adobe contribute mac download windows 7 ultimate 64 bit symantec norton 360 download buy adobe photoshop elements 5.0 autodesk mudbox best price purchase windows xp sp3 autodesk inventor professional 2009 download where can i buy ms office 2003 turbotax cheap adobe after effects trial dreamweaver mac download buy contribute 3 microsoft powerpoint 2003 download windows 7 ultimate oem price autocad electrical 2010 download buy office 2003 license autodesk mudbox price purchase windows 7 activation key microsoft office 2003 download full version buy dvd moviefactory 6 download download microsoft project 2003 windows vista business cost adobe acrobat cheap buy cs3 master collection purchase vista product key download autosketch 9 buy autocad architecture buy autocad inventor 2010 how to buy windows vista product key adobe premiere pro cs3 system requirements buy photoshop cs3 cheap buy windows xp professional download microsoft digital image suite 2006 turbotax pricing buy adobe fireworks cs3 adobe photoshop elements 6 download buy microsoft mappoint 2009 download adobe illustrator cs3 adobe photoshop elements 8 purchase microsoft streets and trips 2010 price buy autocad cheap purchase indesign cs4 windows 7 buy oem autodesk autocad 2010 price purchase windows xp license buy lightroom 1 adobe audition buy windows 7 ultimate cost ms works 9.0 windows vista business 64 bit oem buy ms outlook 2007 buy windows 7 home premium oem buy microsoft office canada buy vista product key online buy windows 7 oem key cheap windows xp pro buy adobe cs4 design premium mac indesign for mac download windows 7 pro sale download quickbooks premier 2007 cheap flash cs4 microsoft office 2003 product key adobe cs4 master collection discount office 2008 for mac download buy windows 7 ultimate price buy windows 7 ultimate product key buy office 2003 online windows vista home basic 64 bit product key adobe contribute review cheapest windows 7 ultimate oem microsoft mappoint 2009 cost cheapest windows 7 pro buy office 2008 for mac product key buy windows vista ultimate cheap windows vista home basic system requirements buy autocad where to buy windows xp license get autocad 2010 buy adobe indesign cs3 mac download autodesk lustre robohelp price how to buy powerpoint 2007 buy cs3 corel draw x4 download windows 7 costs buy windows 2008 server purchase cubase 5 norton 360 buy download autocad mechanical 2009 download get parallels desktop 4.0 for mac buy photoshop elements 7.0 download microsoft mappoint 2009 europe cubase 5 buy buy windows 7 professional oem download adobe premiere pro cs3 mac download microsoft money 2007 deluxe buy premiere cs4 buy windows 7 download adobe premiere pro for mac buy microsoft money plus home & business cheap dreamweaver cs3 buy ms project standard turbotax price autocad 2010 buy buy cs4 photoshop buy dreamweaver cs4 online buy windows 7 family pack download adobe photoshop elements 5.0 cheap windows xp os windows vista business 64 bit sp2 buy microsoft office 2003 standard download adobe framemaker 9 buy windows 7 digitally buy ms office 2003 online windows vista home premium download cheapest norton 360 3.0 windows vista business download master collection cs3 download buy corel draw for mac download adobe premiere full version autodesk inventor professional 2010 price cheap windows vista ultimate adobe captivate student discount download microsoft autoroute 2007 europe purchase windows 7 oem quicken 2008 download autodesk architecture 2010 buy windows vista 64 bit download quicken rental property manager 2009 windows 2008 web server download windows 7 home premium oem pricing windows vista 64 bit purchase quicken 2010 pricing download autocad electrical 2010 buy windows 7 license key windows xp best price 3ds max 2009 download adobe indesign cs3 price download wavelab 5 autodesk electrical 2009 buy office 2003 pro buy dreamweaver cheap download adobe cs4 master collection purchase office 2003 professional buy norton 360 3.0 buy access 2003 online cheap windows 7 for students buy microsoft money deluxe where to buy microsoft frontpage buy quickbooks enterprise solutions cheap dreamweaver download download autodesk autosketch 9 windows vista 64 bit buy windows 7 pro 64 bit price maya price adobe cs4 web premium for mac autodesk 3ds max 2010 torrent microsoft access 2007 buy online buy adobe cs3 master collection quicken 2010 download buy microsoft project 2003 photoimpact download buy windows 7 licence buy windows xp with sp2 microsoft works 9 product key buy windows xp product key online buy adobe photoshop cs3 buy contribute cs3 windows 7 home premium 64 oem windows 7 ultimate 64 bit product key buy windows enterprise mudbox price windows 2008 enterprise download download adobe fireworks cs4 purchase office 2003 license buy microsoft expression web 3 download adobe photoshop elements 6 zonealarm antivirus 8 torrent autocad electrical 2010 price steinberg cubase 4 download microsoft powerpoint cheap excel 2003 to buy download photoshop for mac buy pcanywhere buy cheap adobe illustrator buy maya 2009 unlimited cheap norton 360 antivirus adobe flash for mac quicken 2010 discount money deluxe download purchase microsoft excel windows xp sp3 iso corel draw coupon code buy autoroute 2007 download microsoft powerpoint 2003 buy norton 360 download adobe contribute cs4 for mac adobe premiere download autocad architecture 2010 download buy adobe design premium cs4 buy windows 7 upgrade windows vista download cheapest windows 7 family pack download windows vista home premium adobe indesign download microsoft project 2007 download autocad mechanical 2010 download buy pcanywhere 12.5 adobe captivate 4 price buy dreamweaver cs3 for mac wavelab price buy adobe creative suite 4 design premium download mappoint europe 2009 mappoint 2009 north american maps buy adobe flash cs4 for mac ms excel 2003 download buy maya 2010 adobe font folio price buy cubase studio 4 buy windows 7 ultimate full version buy indesign cs3 mac buy adobe flash cs4 professional autocad architecture oem buy adobe photoshop cs4 extended adobe acrobat 9 oem microsoft money home and business download buy microsoft windows 7 professional buy photoshop cs3 turbotax deluxe 2009 price adobe captivate 3 download buy adobe photoshop elements buy sql server 2008 windows 2008 server pricing windows 7 home premium cheapest windows 2008 standard price adobe photoshop cs3 mac adobe framemaker 9 price download autodesk 3ds max 2008 adobe cs3 master collection price microsoft works download cs4 dreamweaver download download adobe creative suite 3 design premium buy windows 7 ultimate cd key quickbooks enterprise discount adobe pagemaker price buy wavelab adobe premiere elements price purchase corel draw x4 buy frontpage online windows xp buy product key download microsoft office 2003 full version microsoft office project professional 2003 complete package autocad electrical 2010 system requirements purchase windows 7 half price turbo tax best price buy adobe indesign for mac adobe creative suite 4 design premium download buy microsoft outlook 2007 online download microsoft office 2003 pro corel painter for mac buy cs4 design standard buy adobe contribute cheap download lightroom 2 buy microsoft outlook 2007 product key purchase norton 360 buy office onenote 2003 autodesk lustre buy windows 7 home premium best price access pricing autodesk lustre 2010 price buy adobe cs4 master collection corel photoimpact x3 download windows vista home basic price buy navisworks dreamweaver for mac price corel draw price ms streets and trips 2008 download buy autocad electrical 2010 adobe indesign cs4 download buy ms office 2003 standard windows 2003 datacenter pricing download corel video studio 12 mac corel painter windows 2008 datacenter cost other buy windows xp licence key windows vista best price buy ms visio 2007 buy windows 7 ultimate download buy microsoft visio professional buy ms word 2007 buy mudbox 2010 buy microsoft powerpoint 2007 autodesk maya download buy maya 2009 buy adobe premiere elements 8 buy microsoft word 2003 online download autodesk inventor office 2003 download full version autocad 2010 torrent buy visual studio 2003 autodesk inventor professional suite 2010 windows 7 professional oem pricing purchase microsoft access windows vista home basic 32 bit oem windows 2003 datacenter edition buy cubase 5 dongle buy adobe illustrator adobe photoshop cs4 mac download cheapest turbotax 2009 buy windows 2003 datacenter buy windows 7 oem version buy windows vista online buy microsoft office online navisworks manage price buy turbotax 2007 buy windows 7 ultimate 64 bit buy lightroom for mac windows vista home basic buy microsoft digital image suite 9 buy windows 2003 license buy onenote 2007 buy ms excel 2003 download microsoft powerpoint 2007 buy microsoft office 2003 product key buy ms office 2010 adobe photoshop mac price navisworks pricing microsoft office 2003 license key buy windows xp cheap buy quickbooks enterprise buy office 2003 professional windows 7 home premium 64 bit iso buy microsoft access 2003 download adobe cs4 design premium for mac get autocad electrical 2010 download microsoft office 2003 professional edition buy windows vista home premium 32 bit buy windows vista home premium product key windows 7 cost too much buy quickbooks pro 2007 office onenote 2003 download where can i buy autodesk maya purchase adobe premiere pro cs3 design premium cs3 download adobe photoshop cs3 discount windows 7 home premium oem norton 360 sale turbotax discount code buy acrobat 7 buy adobe creative suite 3 master collection buy windows 7 home premium product key buy excel 2003 download buy nuendo 4 adobe photoshop elements 6.0 download price windows 7 ultimate buy windows 7 oem ultimate trial adobe after effects cs3 for mac autocad electrical sales download frontpage express buy autodesk maya 2009 norton 360 download adobe photoshop cs4 mac purchase windows vista online download adobe after effects cs4 cheap windows 7 ultimate key cheap microsoft powerpoint buy microsoft encarta autodesk autosketch price buy quicken 2010 premier cheap windows 7 software adobe illustrator cs4 download adobe photoshop cs3 sale microsoft office 2003 professional where can i buy powerpoint 2007 buy autoroute 2009 buy steinberg nuendo 4 autodesk maya 2009 download photoshop for cheap buy microsoft access only windows xp sp3 download full buy windows 7 pro 64 download microsoft digital image suite 10 adobe contribute pricing autocad electrical oem adobe lightroom discount code purchase windows xp service pack 2 pcanywhere buy navisworks price streets and trips 2010 best buy windows 7 ultimate pricing buy powerpoint 2007 nuendo price adobe pagemaker cost buy lightroom 2.4 buy adobe captivate 3 buy adobe illustrator 10 buy microsoft vista online cheap indesign software adobe premiere elements 8 best buy cheap adobe premiere pro mac download windows vista business 64 bit microsoft expression price cheap autocad 2009 download lightroom 2.5 lightroom cheapest microsoft word 2003 online download parallels desktop 4.0 for mac system requirements windows vista download full version windows xp buy online buy microsoft visual studio 2008 professional buy adobe photoshop elements 6 corel video studio download autocad 2010 download full adobe captivate trial photoshop elements price web premium cs4 download adobe suite for mac cheapest microsoft office for mac mudbox download buy captivate 3 buy quickbooks premier 2010 quickbooks enterprise cost buy microsoft office for mac cheap

Adventures in JSF 2.0: Hello World Tutorial using Maven 2, JSF 2, Facelets 2, and Weld

By Steven Boscarine in Information Technology| People Who Make Software| Uncategorized

17 Oct 2009

In the first of many posts regarding the recently finalized JSF 2.0, I will be showing you what you need to do to write a simple Hello World Application. Instead of traditional JSF backing beans, this application will use Weld, an open-source implementation of JSR-299: Contexts and Dependency Injection for the Java EE platform. JSR-299 will be part of the upcoming JEE 6 specification.

Prerequisites:

Install Sun’s JDK 6, the latest version of Maven (presently 2.2.1), and the IDE of your choice.  I use Eclipse, but GEdit or notepad would work just fine. For this demo, I’ll be using Jetty, so you won’t need to install a container of any sort.

Getting Started:

Create Empty Project

Our first step is to create an ordinary empty WAR project in Maven using the

archetype:generate

command in the directory of your choice.

cd ~/workspace #this can obviously be anywhere.
mvn archetype:generate -DinteractiveMode=n -DarchetypeArtifactId=maven-archetype-webapp -Dversion=0.0.1-SNAPSHOT -DgroupId=org.bogus -DartifactId=jsf2_tutorial

Unfortunately, the default Maven archetype falls short of what we need, so we need to make a few extra directories.  We need a java directory and the test java and resources directory. I’ve also added the commands that an eclipse user would use to generate an importable eclipse project. Netbeans and IntellJ users can simply import the pom.xml.

#create a few extra directories for the project.
mkdir jsf2_tutorial/src/test jsf2_tutorial/src/test/java jsf2_tutorial/src/test/resources jsf2_tutorial/src/main/java
cd jsf2_tutorial
#if you're using *NIX, you can create empty files with this command.
mkdir src/main/java/org/ src/main/java/org/bogus/ #need to create package first.
touch pom.xml src/main/webapp/WEB-INF/web.xml src/main/webapp/WEB-INF/beans.xml src/main/java/org/bogus/HelloWorld.java src/main/webapp/index.xhtml src/test/resources/jetty-env.xml

Overview

I was very impressed that a simple Hello World project can be created with as little as five artifacts.

  1. /pom.xml
  2. /src/main/webapp/WEB-INF/web.xml
  3. /src/main/webapp/WEB-INF/beans.xml
  4. /src/main/java/org/bogus/HelloWorld.java
  5. /src/main/webapp/index.xhtml
  6. /src/test/resources/jetty-env.xml (for Jetty users).

Writing the actual Code

pom.xml

The first step is to the pom.xml file. Afterwards it can be easily imported into any modern IDE.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.bogus</groupId>
	<artifactId>helloworld</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>JSF 2.0 Tutorial</name>
	<repositories>
		<!-- As of October 2009, a few of the weld dependencies were not yet on the main maven repo.  We can add JBoss repo as it is updated more frequently.  -->
		<repository>
			<id>repository.jboss.org</id>
			<name>JBoss Repository</name>
			<url>http://repository.jboss.org/maven2</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
	<dependencies>
		<!-- Common -->
		<dependency>
			<groupId>javax.enterprise</groupId>
			<artifactId>cdi-api</artifactId>
			<scope>provided</scope>
			<version>1.0-CR1</version>
		</dependency>
 
		<dependency>
			<groupId>javax.annotation</groupId>
			<artifactId>jsr250-api</artifactId>
			<version>1.0</version>
		</dependency>
 
		<dependency>
			<groupId>javax.faces</groupId>
			<artifactId>jsf-api</artifactId>
			<version>2.0.0-RC</version>
		</dependency>
 
		<!-- Jetty-specific scopes and artifacts -->
		<dependency>
			<groupId>javax.faces</groupId>
			<artifactId>jsf-impl</artifactId>
			<scope>runtime</scope>
			<version>2.0.0-RC</version>
		</dependency>
 
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
			<scope>runtime</scope>
		</dependency>
 
		<dependency>
			<groupId>org.jboss.weld.servlet</groupId>
			<artifactId>weld-servlet</artifactId>
			<version>1.0.0-CR1</version>
			<scope>runtime</scope>
		</dependency>
 
		<dependency>
			<groupId>org.glassfish.web</groupId>
			<artifactId>el-impl</artifactId>
			<version>2.1.2-b04</version>
			<scope>runtime</scope>
			<exclusions>
				<exclusion>
					<groupId>javax.el</groupId>
					<artifactId>el-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
	<build>
		<finalName>jsf2</finalName>
		<plugins>
			<!-- Compiler plugin enforces Java 1.6 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
 
			<!-- Eclipse plugin enforces download of source and JavaDoc jars -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-eclipse-plugin</artifactId>
				<configuration>
					<wtpversion>2.0</wtpversion>
					<downloadSources>true</downloadSources>
					<downloadJavadocs>true</downloadJavadocs>
				</configuration>
			</plugin>
			<!-- Embedded Jetty (jetty:run) -->
			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>maven-jetty-plugin</artifactId>
				<configuration>
					<!-- force friendly name instead of artifact name + version -->
					<contextPath>${build.finalName}</contextPath>
					<!-- Where the BeanManager is constructed.  This is where we'll later declare datasource. -->
					<jettyEnvXml>${basedir}/src/test/resources/jetty-env.xml</jettyEnvXml>
					<!-- This parameter will auto-deploy modified classes...my personal favorite Jetty feature. -->
					<scanIntervalSeconds>3</scanIntervalSeconds>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

Now that your pom is complete, you can import it into the IDE of your choice. Eclipse requires users to either install m2eclipse or run:

mvn eclipse:eclipse

Boilerplate

web.xml

Since JSF 1.2, the web.xml page got a lot smaller. This is where convention over configuration pays off. Also, faces-config.xml is now optional!

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
	<!-- Standard JSF 2.0 Configuration Paramters. -->
	<!-- No Joke!!...This is all you need now! -->
	<context-param>
		<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
		<param-value>.xhtml</param-value>
	</context-param>
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.jsf</url-pattern>
	</servlet-mapping>
 
	<!-- Weld Jetty Configuration parameters -->
	<listener>
		<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
	</listener>
	<resource-env-ref>
		<description>Object factory for the CDI Bean Manager</description>
		<resource-env-ref-name>BeanManager</resource-env-ref-name>
		<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
	</resource-env-ref>
</web-app>

beans.xml

In order to indicate to weld to initialize dependency injection, you’ll need to create an empty file named beans.xml. The mere presence of this file in your WEB-INF folder tells the container that your WEB-INF/classes folder is a bean deployment archive.

Application-Specific Code

HelloWorld.java

To confirm that Weld (A.K.A. JSR 299 or WebBeans) Dependency Injection works, we’re going to write an incredibly simple bean. In contrast to Spring, you don’t need to declare the package or bean. Simply adding the @Named annotations and declaring a scope is all that is needed to have your bean registered with the dependency injection container and visible to your facelets view pages.

package org.bogus;
 
import java.io.Serializable;
 
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
 
@Named //assigns this bean the name of "helloWorld"...its "de-caplitalized" class name
@SessionScoped  //creates one bean for each user session.
public class HelloWorld implements Serializable {
	private final String text = "Hello World!";
 
	public String getText() {
		return text;
	}
 
	private static final long serialVersionUID = 1L;
}

index.xhtml

Now we want to actually view the bean we created. Below is an incredibly simple xhtml/facelets page.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<h:head>
	<title>JSF Demo</title>
</h:head>
<h:body>
	<h1>Does Weld Work?</h1>
	<!-- Your bean can be easily accessed via Expression Language -->
	<p>My weld-injected bean says: #{helloWorld.text}</p>
</h:body>
</html>

jetty-env.xml

Since we’re not using a full JEE container, we need to configure Jetty to prepare the BeanManager.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
   "http://jetty.mortbay.org/configure.dtd">
<Configure id="webAppCtx" class="org.mortbay.jetty.webapp.WebAppContext">
	<New id="appManager" class="org.mortbay.jetty.plus.naming.Resource">
		<Arg>
			<Ref id="webAppCtx" />
		</Arg>
		<Arg>BeanManager</Arg>
		<Arg>
			<New class="javax.naming.Reference">
				<Arg>javax.enterprise.inject.spi.BeanManager</Arg>
				<Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
				<Arg />
			</New>
		</Arg>
	</New>
</Configure>

Start up Jetty

Jetty is an embedded servlet container that can be easily launched from Maven. Since we added that small snippet to the pom, we can simply type:

mvn war:inplace jetty:run

…and maven will download Jetty and run it with the configuration file we passed.

Test Your Application

Simply load http://localhost:8080/jsf/index.jsf

firefox http://localhost:8080/jsf/index.jsf

Screenshot of your application
If you see the hello world text, everything has worked. Now that you’ve confirmed your configuration is setup correctly, you can explore the more interesting features of Weld and JSF 2, which I’ll be covering in future posts.

Download the Code

The source code to this tutorial is available via subversion here

UPDATE: Tomcat Users

With the addition of a context.xml, this example runs perfectly on Tomcat.
Please see this article for details.

Further Reading

Many thanks to the JBoss staff on the forums who helped me get started in Weld. The artifacts in this article were modeled after their examples.

19 Responses to Adventures in JSF 2.0: Hello World Tutorial using Maven 2, JSF 2, Facelets 2, and Weld

Avatar

sheff

October 23rd, 2009 at 3:01 am

It was useful. This post is very good start point for these technologies.
Thank you.

Avatar

Daniel

October 23rd, 2009 at 3:02 am

Great tutorial but Mojarra is now final. See https://javaserverfaces.dev.java.net/maven2

Avatar

Murat Can ALPAY

October 23rd, 2009 at 8:21 am

‘My weld-injected bean says’ well nothing.
I added logging and couldn’t see anything relevant on the console either.
It logs “Weld initialized. Validating beans.” for the last thing but on requesting
http://localhost:8080/jsf2/index.jsf
I don’t see the ‘Hello World’ text.

Avatar

Steven Boscarine

October 23rd, 2009 at 11:20 am

Hello Murat Can ALPAY,
Thanks for commenting. Did you remember the beans.xml file? It can be an empty file.

If that doesn’t fix it, please try downloading the source from the svn link and see if it works. On the subversion version, I added a no-args constructor with a System.out.println() call that’ll print “HelloWorld was constructed” to the console.

Thanks,
Steven

Avatar

Gurkan Erdogdu

October 24th, 2009 at 9:27 am

You can also use OpenWebBeans in Jetty, Tomcat. It contains examples that shows how to use it in JSF, EJB , JMS etc.

Source Location:
https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/samples

reservation : mvn jetty:run -Pjetty
guess : mvn jetty:run -Pjetty

Main Site:
http://incubator.apache.org/openwebbeans

–Gurkan

Avatar

Murat Can ALPAY

October 26th, 2009 at 4:33 am

if I run the project with the jetty:run it doesn’t work. if I deploy it as a exploded war through my idea it works fine. I am not really experienced with maven probably my bad…
Thanks,
Murat

Avatar

Steven Boscarine

October 26th, 2009 at 9:37 am

You need to run mvn war:inplace jetty:run, not just jetty:war. Add that command and I think everything will run as expected.

I am not sure precisely why war:inplace is required. I asked the JBoss folks that question this weekend. This is the first time I’ve seen anyone use war:inplace. As soon as I get the answer, I’ll post an update explaining it.

Also, if you prefer tomcat, I added an addendum on deploying the examples in tomcat at http://info.rmatics.org/2009/10/24/jsf2_tutorial_0b/. Simply add a context.xml file and you can deploy your war to Tomcat. It’s really easy.

Hope that helps!
Steven

Avatar

Sten Aksel Heien

October 28th, 2009 at 6:10 am

Nice intro. Looking forward to next articles :-)

Avatar

Steve Berczuk

November 6th, 2009 at 3:48 pm

Another option to consider (also related to the next post about deploying to Tomcat) is the maven tomcat plugin in embedded mode (http://mojo.codehaus.org/tomcat-maven-plugin). That makes the differences between test an development even less, including the ability to use a “Server” context.xml.

Avatar

Steven Boscarine

November 6th, 2009 at 4:09 pm

Hello Steve,
Good point and thanks for commenting. I actually posted about embedded tomcat in one of my very first blog posts. (http://info.rmatics.org/2009/04/02/increasing-your-productivity-by-using-an-embedded-container-in-maven/).

I tested the with the embedded Tomcat and it wasn’t working when this post was written. As of today, the embedded plugin runs Tomcat 6.0.16, which unfortunately doesn’t work with Weld. Tomcat 6.0.20, however, works perfectly with the examples.

Hopefully the embedded tomcat plugin will get updated soon and Weld will run perfectly on it.

Thanks,
Steven

Avatar

Gene De Lisa

November 18th, 2009 at 8:45 am

In contrast to Spring, you don’t need to declare the package or bean. Simply adding the @Named annotations and declaring a scope is all that is needed to have your bean registered with the dependency injection container

Sorry but that’s misinformed or JBoss propaganda. The following sentence is true for Spring:

Simply adding the @Component annotations and declaring a scope is all that is needed to have your bean registered with the dependency injection container

Avatar

Steven Boscarine

November 18th, 2009 at 10:56 am

Hello Gene.
Thank you for responding and I appreciate your pushback.

However, your statement is only correct in existing applications spring-enabled applications where your package has been previously registered. Also, Spring doesn’t really handle scoping. Spring IOC handles singleton and non-singleton (the equivalent of @Request). You have to use WebFlow to get Conversation or Session scoping.

As far as JBoss propaganda or being misinformed. I am actually a Spring 2.5 user migrating towards CDI. Weld is just an implementation of JSR 299, part of JEE 6. I’m not sure of the reason why, but Spring didn’t feel like contributing to the JSR, so it is led by Gavin King of JBoss. You could easily use the Apache implementation of CDI (OpenWebBeans) if you had issues with JBoss.

The difference between CDI and Spring 2.5 is that by adding an empty beans.xml file, you’re ready to start using CDI. To write the same tutorial in Spring, I would have to:

1. Create a Spring config.
2. Register EACH package in the config.
3. Modify your web.xml to initialize the Spring listener.
4. Modify your face-config.

In the end, you still couldn’t declare a bean as @ConversationScoped through Spring.

CDI is not a revolutionary improvement over Spring IOC so much as it’s an evolutionary improvement. I personally still like Spring and would not be so enamored with CDI if Spring had decent, first-class integration with JSF. SpringSource added JSF integration as a afterthought with WebFlow and it is very cumbersome to use for anything other than long multi-page flows.

If you use JSF, CDI is a huge improvement over Spring. If you don’t, then it’ll do a few things slightly better, but probably isn’t worth gutting your entire infrastructure out for if you’re already invested in a non-JSF-webframework.

The specifications and implementation of the various components of JEE6 are just now getting finalized. They have excellent APIs and potential. Once greater integration and testing documentation is out in the wild, I think you’ll find JEE6 to be a compelling alternative to whatever you’re using now.

Thanks again for reading and responding,
Steven

Avatar

Alberto Gori

November 21st, 2009 at 6:42 am

You can run the example using command

mvn clean package jetty:run-war

just putting the jetty-evn.xml file into the webapp/WEB-INF folder.

Avatar

Tai

November 23rd, 2009 at 1:58 am

Hi,

I have a problem with setting up this example under Windows. I am not familiar with Maven but I get stuck with the command:
touch pom.xml src/main/webapp/WEB-INF/web.xml src/main/webapp/WEB-INF/beans.xml src/main/java/org/bogus/HelloWorld.java src/main/webapp/index.xhtml src/test/resources/jetty-env.xml

The touch command and I figured out that it is part of a mvn plugin. I have also tried calling “mvn touch …” but I only get this a “BUILD FAILURE” with:
Invalid task ‘touch’: you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal

Can anybody Help?

Thanks in advance,
Tai
P.S.: using mkdir under windows you have to replace “/” with “\”

Avatar

Steven Boscarine

November 23rd, 2009 at 10:02 am

Hello Tai,
You are correct. Those commands are for *NIX. You can install cygwin if you really want to run them, however, there’s an easier way to accomplish the same goals.

Touch in *NIX simply creates an empty file. I added that command to reduce the chances of someone forgetting to create a file or putting it in the wrong directory. For example one user had issues because he forgot to create the empty beans.xml file. The touch command is designed to avoid that.

Simply create the folders and files in the Overview section in Windows explorer or eclipse and move on to writing the actual code.

If you want to work on your Maven skills and skip the manual steps, there’s an even easier way. I’ve been working with the kind folks at JBoss to create maven archetype that creates all the files you need to get started.

The instructions are here: http://www.seamframework.org/Documentation/WeldQuickstartForMavenUsers Once these archetypes get published to the maven repo (hopefully soon), this entire tutorial becomes 2 maven commands. For now, you have to check out the code and build it.

Finally, I included my original source in the “Download the Code” section if you want to just have a working project to play with.

Thanks for commenting and checking out Weld.

In the last month, I have been working with the Weld team to try to make CDI and Weld as accessible and easy to use as possible to new users. Hopefully, in a month or 2, users in your situation will find it CDI and JSF 2.0 incredibly easy to get started with.

Thanks,
Steven

Avatar

Martin

December 6th, 2009 at 12:19 pm

As Murat Can ALPAY, I get nothing. But I noticed the following in the log output:
Dec 6, 2009 5:55:56 PM org.jboss.weld.environment.servlet.Listener contextInitialized
INFO: JSR-299 injection will not be available in Servlets, Filters etc. This facility is only available in Tomcat
Dec 6, 2009 5:55:56 PM org.jboss.interceptor.model.InterceptionTypeRegistry

Creating the war file and deploying to Tomcat works fine though.

Regards,

Avatar

Ashley Westwell

January 8th, 2010 at 7:08 am

Hey

I tried your example and it works fine, thanks for the quick start. However if I try to update the JSF 2 dependencies to latest version the injection stops working!

Here is what I changed the JSF dependancies to in the pom.xml

From

javax.faces
jsf-impl
runtime
2.0.0-RC

javax.servlet
jstl
1.2
runtime

To

javax.faces
jsf-api
2.0.2-FCS

javax.faces
jsf-impl
runtime
2.0.2-FCS

Avatar

Ashley Westwell

January 8th, 2010 at 7:09 am

Type above

javax.servlet
jstl
1.2
runtime

Should be

javax.faces
jsf-impl
runtime
2.0.0-RC

Avatar

Steven Boscarine

January 8th, 2010 at 9:22 am

Hello Ashley,
I apologize, but much as changed since that post was written. When that post was written, there were no weld archetypes. Since then, I got a chance to work with the JBoss team to create archetypes to automate the entire procedure.

Please try this procedure instead: http://www.seamframework.org/Documentation/WeldQuickstartForMavenUsers

I’ll update that post to reflect the fact that nearly the entire tutorial has been reduced to a few command lines. The JBoss team is actively working with the community to make adopting Java EE features as easy as possible with projects like the archetype project.

Thanks,
Steven

Comment Form

About this blog

A group of people dedicated to figuring out clever ways to implement information technology in healthcare. It's written by William Crawford, Jon Abbett, Evan Pankey, Vineet Manohar and Steven Boscarine.

  • Aruna: hi Steven, Thanks for this great tutorial. I'm new to all this stuff maven, jsf, tomcat etc. I lo [...]
  • Steven Boscarine: Hello Ashley, I apologize, but much as changed since that post was written. When that post was writ [...]
  • Ashley Westwell: Type above javax.servlet jstl 1.2 runtime Should be javax.faces jsf-impl runtime 2. [...]
  • Ashley Westwell: Hey I tried your example and it works fine, thanks for the quick start. However if I try to updat [...]
  • Steven Boscarine: Corrected. Good catch and thank you for pointing it out, Matt. Apologies to Dan. [...]