sildenafil kaufen cialis prezzo kamagra pas cher viagra dosaggio acheter cialis generic impuissance erection viagra farmacia acheter levitra pas chere acheter clomid en france curare impotenza aquisto levitra sildenafil sin receta vendita viagra achat viagra le viagra viagra donna cialis inde cialis marche pas genericos viagra pildoras cialis cialis belgique levitra venta pilule viagra acheter kamagra 100mg levitra italia impotenza sessuale achat de levitra cialis generique acheter acquisto viagra on line levitra donne viagra versand tadalafil precio cialis en ligne vardenafil generique acheter cialis 20mg impuissance sexuelle cialis meilleur prix commander du cialis viagra ohne rezept acheter cialis pas cher kamagra te koop vardenafil generico vendo viagra pastilla cialis farmaci impotenza levitra sin receta cialis ohne rezept generische viagra levitra te koop sildenafil precio acheter kamagra france acheter viagra pas chere vardenafil bestellen cialis livraison rapide viagra bestellen acheter propecia vendita levitra propecia sans ordonnance achat levitra cialis pharmacie cialis venta cialis vente en ligne viagra controindicazioni posologia viagra cialis 10 mg leivtra moins cher cialis prijs generique du viagra cialis prescrizione procurer du levitra acheter cialis sans ordonnance kamagra apcalis vendo sildenafil achat cialis 20mg vente levitra pastilla viagra comprar viagra em portugal comprar cialis generico levitra naturale levitra venta libre aquisto cialis cialis donne koop viagra vardenafil generika viagra recensioni levitra generico acheter accutane impuissance homme prozac sans ordonnance acquisto viagra generico receta viagra levitra pharmacie vardenafil generico tadalafil bestellen vendo viagra milano viagra 50 mg compro sildenafil acquisto levitra acheter zithromax levitra prix cialis sur internet vente viagra cialis generico 10 mg cialis pharmacie prix viagra pharmacie acheter cialis cura impotenza viagra donne viagra naturel cialis generique cialis sur ordonnance viagra svizzera cialis kopen cialis en pharmacie compro cialis sildenafil generico acheter cialis generique achat kamagra internetapotheke acquistare levitra viagra moins cher zyban generique acheter du cialis viagra europe kamagra rezeptfrei impotenza rimedi prix du cialis levitra generique cialis moins cher commander kamagra costo levitra pharmacie en ligne

Side Adventures in JSF 2.0: Deploy the Hello World example in Tomcat.

By Steven Boscarine in Uncategorized

24 Oct 2009

In a previous post. I showed how to do the absolute bare minimum to get a CDI/Weld project running in Jetty. Jetty is my favorite container because when launched from maven, it automatically redeploys classes as you modify them without configuring my IDE.

However, in every Java job I’ve ever held, the final product is deployed to another container, such as Tomcat. Fortunately, the Tomcat web application is almost identical to Jetty. Just take the identical application, add a context.xml and deploy.

Create context.xml

#from your project home directory (where pom.xml lives)
touch src/main/webapp/META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
	<Manager pathname="" /> <!-- disables storage of sessions across restarts -->
	<Resource name="BeanManager" auth="Container" type="javax.enterprise.inject.spi.BeanManager" 
		factory="org.jboss.weld.resources.ManagerObjectFactory" />
	<!-- Uncomment to enable injection into Servlet -->
	<!-- <Listener className="org.jboss.weld.environment.tomcat.WeldLifecycleListener"/> -->
</Context>

Now, build the project using the standard Maven way:

mvn clean package

In your target directory, you’ll find a war you can deploy using tomcat manager.

Automate Tomcat Deployments using Cargo

If you’re like me, you hate doing things more than once when a script can do the job for you. Simply add:

<!-- Cargo - deploys to Tomcat using command 'mvn clean package cargo:redeploy'. -->
<plugin>
	<groupId>org.codehaus.cargo</groupId>
	<artifactId>cargo-maven2-plugin</artifactId>
	<configuration>
		<container>
			<containerId>tomcat6x</containerId>
			<type>remote</type>
		</container>
		<configuration>
			<type>runtime</type>
			<properties>
				<!-- Declare a tomcat.user and tomcat.password in your settings file -->
				<cargo.remote.username>${tomcat.username}</cargo.remote.username>
				<cargo.remote.password>${tomcat.password}</cargo.remote.password>
				<!--defaults to localhost:8080-->
				<!--<cargo.hostname>localhost</cargo.hostname>-->
				<!--<cargo.servlet.port>8080</cargo.servlet.port>-->
			</properties>
		</configuration>
	</configuration>
</plugin>

If you have a settings.xml file in your .m2 directory, then add the tomcat.username and tomcat.password variables. If you don’t have one, create a file named settings.xml in ~/.m2/

touch ~/.m2/settings.xml

If you have not yet declared a settings.xml, use the one below to get started and add your manager username and password.

settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<profiles>
		<profile>
			<id>default</id>
			<properties>
				<tomcat.username>(a valid tomcat user in 'manager' role)</tomcat.username>
				<tomcat.password>(the manager password)</tomcat.password>
			</properties>
		</profile>
	</profiles>
	<activeProfiles>
		<activeProfile>default</activeProfile>
	</activeProfiles>
</settings>

Ready to deploy

Now you can deploy to localhost:8080 using the command below.

mvn clean package cargo:redeploy

The host and port can be configured by setting cargo.hostname and cargo.servlet.port.

All Done

Now you can deploy your application to tomcat automatically.

Further Reading

1 Response to Side Adventures in JSF 2.0: Deploy the Hello World example in Tomcat.

Avatar

Aruna

January 30th, 2010 at 6:29 am

hi Steven,
Thanks for this great tutorial.
I’m new to all this stuff maven, jsf, tomcat etc.
I lost when you said to do “Automate Tomcat Deployments using Cargo”. I searched hours to put that code block. Finally found that. we need to put that on pom.xml file.

I found that here.

http://cargo.codehaus.org/Maven2+Plugin+Installation
Thanks.

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.

  • Bee: I manage to get it running on tomcat 5.5.x. Thanks. [...]
  • Bee: Thanks for the great tutorial. I wonder if it can be run in tomcat 5.5.x. I mean if JSF 2.0 and Weld [...]
  • 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. [...]