You are looking at documentation for an older release. Not what you want? See the current release documentation.
The source code used in this tutorial is here.
Juzu framework offers the following features to ease portlet development:
Be able to develop your portlet like a standalone application, and simply use the @Portlet annotation to make it a portlet.
Live mode: no need to re-deploy your application, because changes are applied when you save your files.
Templating: use Groovy, type safe parameters, template validation at compilation.
Dependency injection - JSR-330 (CDI, Spring, Guice).
Modular architecture with plugins.
References
Juzu documentation: http://juzuweb.org - learn directly from this site where Juzu team will update tutorials, references and Javadocs.
Juzu source code: https://github.com/juzu/juzu.
This tutorial focuses on Juzu portlet deployment in eXo Platform Tomcat and JBoss.
The dependencies are different for each server and each dependency injection implementation, so the project will use different Maven build profiles for packaging in each case:
Use mvn clean package -Pplf-tomcat-guice to build a package for Tomcat using Guice.
Use mvn clean package -Pplf-jboss-guice to build a package for JBoss using Guice.
Use mvn clean package -Pplf-tomcat-spring to build a package for Tomcat using Spring.
Use mvn clean package -Pplf-jboss-spring to build a package for JBoss using Spring.
Currently, only Guice and Spring are covered in this tutorial. The other implementation, Weld, will be documented later.
Create a Maven project as follows:
You can use the following archetype to generate project but make sure you will modify every single file in accordance with this tutorial.
mvn archetype:generate -DarchetypeGroupId=org.juzu -DarchetypeArtifactId=juzu-archetype -DarchetypeVersion=1.0.0 -DgroupId=org.exoplatform.samples -DartifactId=hellojz -Dversion=4.2.x
Edit Controller.java
:
package org.exoplatform.samples;
import juzu.Path;
import juzu.View;
import juzu.Response;
import juzu.template.Template;
import javax.inject.Inject;
import java.io.IOException;
public class Controller {
@Inject
@Path("index.gtmpl")
Template index;
@View
public Response.Content index() throws IOException {
return index.ok();
}
}
Edit package-info.java
:
@juzu.Application
@juzu.plugin.servlet.Servlet(value = "/")
package org.exoplatform.samples;
Edit index.gtmpl
:
Hello World
Edit jboss-deployment-structure.xml
:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="deployment.platform.ear" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
Edit portlet.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>SampleApplication</portlet-name>
<display-name xml:lang="EN">Juzu Sample Application</display-name>
<portlet-class>juzu.bridge.portlet.JuzuPortlet</portlet-class>
<init-param>
<name>juzu.app_name</name>
<value>org.exoplatform.samples</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>Sample Application</title>
</portlet-info>
</portlet>
</portlet-app>
Edit web-guice.xml
:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<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_3_0.xsd"
version="3.0">
<!-- Run mode: prod, dev or live -->
<context-param>
<param-name>juzu.run_mode</param-name>
<param-value>${juzu.run_mode:dev}</param-value>
</context-param>
<!-- Injection container to use: guice, spring, cdi or weld -->
<context-param>
<param-name>juzu.inject</param-name>
<param-value>guice</param-value>
</context-param>
</web-app>
Edit web-spring.xml
:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<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_3_0.xsd"
version="3.0">
<!-- Run mode: prod, dev or live -->
<context-param>
<param-name>juzu.run_mode</param-name>
<param-value>${juzu.run_mode:dev}</param-value>
</context-param>
<!-- Injection container to use: guice, spring, cdi or weld -->
<context-param>
<param-name>juzu.inject</param-name>
<param-value>spring</param-value>
</context-param>
</web-app>
Edit pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.exoplatform.samples</groupId>
<artifactId>hellojz</artifactId>
<version>4.2.x</version>
<packaging>war</packaging>
<name>Juzu Application</name>
<properties>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.juzu</groupId>
<artifactId>juzu-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.juzu</groupId>
<artifactId>juzu-plugins-servlet</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<finalName>hellojz</finalName>
</build>
<profiles>
<profile>
<id>plf-tomcat-guice</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>target</name>
<value>plf-tomcat-guice</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
<properties>
<maven.war.webxml>src/main/web-guice.xml</maven.war.webxml>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>
WEB-INF/jboss-deployment-structure.xml,
WEB-INF/lib/*.jar
</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>plf-jboss-guice</id>
<activation>
<property>
<name>target</name>
<value>plf-jboss-guice</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
<properties>
<maven.war.webxml>src/main/web-guice.xml</maven.war.webxml>
</properties>
</profile>
<profile>
<id>plf-tomcat-spring</id>
<activation>
<property>
<name>target</name>
<value>plf-tomcat-spring</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>runtime</scope>
<version>2.5.5</version>
</dependency>
</dependencies>
<properties>
<maven.war.webxml>src/main/web-spring.xml</maven.war.webxml>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>
WEB-INF/jboss-deployment-structure.xml
</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>plf-jboss-spring</id>
<activation>
<property>
<name>target</name>
<value>plf-jboss-spring</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>runtime</scope>
<version>2.5.5</version>
</dependency>
</dependencies>
<properties>
<maven.war.webxml>src/main/web-spring.xml</maven.war.webxml>
</properties>
</profile>
</profiles>
</project>
Here are some remarks:
Dependencies
Juzu:
<dependency>
<groupId>org.juzu</groupId>
<artifactId>juzu-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.juzu</groupId>
<artifactId>juzu-plugins-servlet</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
Guice:
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
Spring:
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.5.5</version>
</dependency>
Note that you can deploy this portlet using Guice in Tomcat and JBoss or using Spring in Tomcat as usual. However, to deploy this portlet using Spring in JBoss, the following dependencies are needed at runtime:
spring-beans-2.5.5.jar
spring-context-2.5.5.jar
spring-core-2.5.5.jar
spring-web-2.5.5.jar
These dependencies have been already packaged in the generated hellojz.war
file. Therefore you can choose to deploy this portlet via the 2 following ways:
Copy these above dependencies from hellojz.war!/WEB-INF/lib/
to $PLATFORM_JBOSS_HOME/standalone/deployments/platform.ear!/lib
, then deploy this portlet as usual.
Deploy the hellojz.war
file into $PLATFORM_JBOSS_HOME/standalone/deployments/platform.ear/
and include it as the first module in the $PLATFORM_JBOSS_HOME/standalone/deployments/platform.ear/META-INF/application.xml
file. The application.xml
file will look like:
...
<display-name>plf-enterprise-jbosseap-ear</display-name>
<initialize-in-order>true</initialize-in-order>
<!-- The first module -->
<module>
<web>
<web-uri>hellojz.war</web-uri>
<context-root>hello-portlet-sample</context-root>
</web>
</module>
<!-- Other modules -->
...