[fleXive] Developer Blog

March 16, 2010

Maven archetype updated, Beta 3 released

Filed under: Development News, Releases, Using fleXive — Tags: , , , , , , — Daniel Lichtenberger @ 16:13

The Maven EAR archetype has been updated after the release of [fleXive] 3.1 Beta 3. It is of course based on beta 3, and includes a few minor changes and bugfixes that justified a new version.

The flexive backend is now always reached under the /flexive context (both from the embedded Jetty instance and from EAR deployments), the application itself always under /war. To get started:

  1. mvn archetype:generate -DarchetypeGroupId=com.flexive -DarchetypeArtifactId=flexive-archetype-ear -DarchetypeVersion=0.7 -DarchetypeRepository=http://repo.flexive.org/maven2/
  2. Enter the project name and group, e.g. test/test
  3. cd test
  4. mvn install
  5. cd war
  6. mvn jetty:run
  7. Open http://localhost:8080/flexive/ in your browser and complete the installation by logging in with supervisor/supervisor.

For more information on the Maven support, please refer to the reference documentation.

August 14, 2009

Maven EAR applications: new H2 version required

Filed under: Development News — Tags: , , , , , , , — Daniel Lichtenberger @ 15:18

The 0.6 version of our EAR archetype includes a hardcoded version number for the H2 database engine artifact. Recent changes in the [fleXive] trunk (i.e. 3.1-SNAPSHOT) require a newer version of H2, otherwise the initialization of the database will fail with a “Syntax error in SQL statement”.

The fix for existing projects is to fix the version number in your main module’s pom.xml: increase the h2.version property from 1.1.106 to 1.1.117.

To avoid this issue in the future, I moved the H2 dependency to the flexive-h2 artifact. The current snapshot version of the archetype (1.0-SNAPSHOT) therefore no longer includes a dependency on com.h2database.h2, and potential changes in the required H2 version number (always a possibility since H2 development is very active) won’t affect existing projects.

April 16, 2009

WAR deployment with EJB 3.1 and Glassfish v3 Preview

Filed under: Development News, Using fleXive — Tags: , , , , , , — Daniel Lichtenberger @ 15:32

Update 2009/07/15: address the Glassfish v3 Preview instead of the older Prelude release.

EJB 3.1 brings the deployment of EJBs as part of a WAR, ultimately removing any entry barriers to using EJBs with a container that supports EJB 3.1. This article will show how to deploy [fleXive] as part of a WAR application, using [fleXive]’s WAR archetype for Maven and Glassfish v3 Preview.

Create the WAR project

To get started, create a new Maven project using our WAR archetype:
mvn archetype:generate -DarchetypeGroupId=com.flexive -DarchetypeArtifactId=flexive-archetype-war -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeRepository=http://repo.flexive.org/maven2/ -DgroupId=my.group.test -DartifactId=webapp-test -Dversion=1.0-SNAPSHOT

This creates a basic WAR application with the following directory structure:

    webapp-test
    |-- pom.xml
    `-- src
        `-- main
            |-- java
            |   `-- my
            |       `-- group
            |           `-- test
            |               |-- EJBExampleBean.java
            |               `-- ExampleBean.java
            `-- webapp
                |-- WEB-INF
                |   |-- faces-config.xml
                |   `-- web.xml
                `-- index.xhtml

EJBExampleBean shows a prime feature of EJB 3.1: instead of having to declare an EJB interface and packaging the EJB class in a separate EJB JAR file, we just add our EJB to the web application and annotate it with @javax.ejb.Stateless (of course, you can still use explicit local and remote interfaces). This turns it into a fully-fledged EJB that can be injected into other managed beans using the @EJB annotation.

@Stateless(name = "EJBExample")
public class EJBExampleBean {

    public Map<FxType, Integer> getInstanceCounts() throws FxApplicationException {
        final Map<FxType, Integer> result = new HashMap<FxType, Integer>();
        final FxEnvironment environment = CacheAdmin.getEnvironment();
        // Invoke fleXive query through EJB and collect the results
        for (FxFoundType foundType : new SqlQueryBuilder().select("@pk").getResult().getContentTypes()) {
            result.put(environment.getType(foundType.getContentTypeId()), foundType.getFoundEntries());
        }
        return result;
    }
}
/**
 * Request-scoped JSF bean accessing the EJB.
 */
public class ExampleBean {
    @EJB EJBExampleBean exampleEJB;
    private Map<FxType, Integer> instanceCounts;

    public Map<FxType, Integer> getInstanceCounts() throws FxApplicationException {
        if (instanceCounts == null) {
            instanceCounts = exampleEJB.getInstanceCounts();
        }
        return instanceCounts;
    }
}

In our pom.xml we add the [fleXive] EJB and JSF artifacts, as well as Glassfish itself to provide the EJB 3.1 APIs during compilation. It seems that Glassfish v3 Preview does not bring Sun’s EL-1.0 implementation (which we need for Facelets), so we have to add this too.

<properties>
    <flexive.version>3.1-SNAPSHOT</flexive.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.flexive</groupId>
        <artifactId>flexive-ejb</artifactId>
        <type>ejb</type>
        <version>${flexive.version}</version>
    </dependency>

    <dependency>
        <groupId>com.flexive</groupId>
        <artifactId>flexive-plugin-jsf-core</artifactId>
        <version>${flexive.version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.el</groupId>
        <artifactId>el-ri</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.javaee</artifactId>
        <version>3.0-Prelude-b28b</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

The pom.xml also expands the [fleXive] EJBs into the WEB-INF/classes folder of the web application, because Glassfish v3 Prelude Preview does not yet support EJB-JAR deployments:

<!--
    Unpack the flexive-ejb artifact and add it to WEB-INF/classes
    (Glassfish v3 Prelude does not support EJB-JAR deployment yet)
-->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <!-- Copy the EJBs to target/flexive -->
        <execution>
            <id>copy-ejb</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.flexive</groupId>
                        <artifactId>flexive-ejb</artifactId>
                        <version>${flexive.version}</version>
                        <overWrite>true</overWrite>
                        <outputDirectory>target/flexive/WEB-INF/classes</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1-beta-1</version>
    <configuration>
        <webResources>
            <resource>
                <directory>target/flexive</directory>
            </resource>
        </webResources>
    </configuration>
</plugin>

Invoke mvn package to compile and package the application into target/webapp-test.war.

Glassfish v3 Prelude Preview setup

Download and install Glassfish v3 Preview.

Before deploying a [fleXive] application, you need to perform additional setup steps described in the reference documentation:

  • Download the [fleXive] distribution
  • Install the required libraries to [glassfish-home]/glassfish/domains/domain1/lib/ext
  • Add the datasources
  • Initialize the database schema as described here

Deploying the WAR application to Glassfish

Finally, start Glassfish with bin/asadmin start-domain and deploy the WAR file from your project directory with [glassfish-home]/bin/asadmin deploy --force=true target/webapp-test.war. Deployment should only take a few seconds, and the application should be running and display the output from calling our EJB at http://localhost:8080/webapp-test/.

A note on JSF2

[fleXive] is a JSF 1.2 application. As such, it should work without changes in a JSF2 container. However, we ran into some issues, mostly due to RichFaces’ Ajax4JSF implementation. In the backend application, you need to force client-side state saving (through a config parameter in the web.xml), and some administration pages don’t work yet. The JSF components themselves appear to be working without problems, however they are still based on JSF 1.2 and Facelets – thus they cannot be used in a true JSF2 application.

November 29, 2008

Getting started with [fleXive] and Maven 2

Filed under: Development News — Tags: , , , , , , , , — Daniel Lichtenberger @ 11:30

Currently the [fleXive] distribution is based on a set of Apache Ant buildfiles for managing [fleXive] JavaEE projects and performing administration tasks like datasource setup. Although this approach allows for a rather convenient development of new [fleXive] applications, it is neither modular nor particularly well-suited for integration in existing projects.

Thus we decided to add support for the other big build tool, Apache Maven 2. Our goal was to provide a modularized version of [fleXive] that can be added to existing Maven applications by adding a few dependencies.

As of today, our (experimental) Maven repository is online at http://repo.flexive.org/maven2/. It provides all [fleXive] libraries with correct dependencies, as well as a project archetype for a [fleXive] application. In this post, I’ll show how to create a new mavenized project and start the application using an integrated servlet container.

  1. If you haven’t done so already, install Apache Maven.
  2. In a local directory, enter the following command:
    mvn archetype:generate -DarchetypeGroupId=com.flexive -DarchetypeArtifactId=flexive-archetype-ear -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeRepository=http://repo.flexive.org/maven2/ -DgroupId=mygroup -DartifactId=hello-flexive -Dversion=0.1-SNAPSHOT

    This will create a new [fleXive]/EAR project in the directory hello-flexive.

  3. cd hello-flexive
  4. mvn install

    This will compile, package and install the sample application in your local repository, and setup the H2 database schema (when run for the first time.)
    Update 2008/12/18: You can still reset the H2 database manually with mvn install -Pflexive-db-setup-h2.

  5. cd war
  6. mvn jetty:run

    We start an instance of the Jetty WebServer to deploy our application (including the [fleXive] backend application) and OpenEJB. You know that Jetty’s ready to handle requests when it prints the line

    [INFO] Started Jetty Server.

    Update: Depending on your system settings, you may need to increase the memory available for Maven 2 by setting the MAVEN_OPTS environment variable (e.g. EXPORT MAVEN_OPTS="-Xmx512M" on Linux or SET MAVEN_OPTS=-Xmx512M on Windows)

  7. Point your web browser at http://localhost:8080/flexive-backend-war/ and login using the default login privileges (supervisor/supervisor). The [fleXive] initialization scripts will execute, and a fully functional [fleXive] installation is at your hands.
  8. The original intention of course was to develop your own application – open http://localhost:8080/war/ to see a very simple [fleXive] application consisting of a JSF page, a JSF bean, and an EJB that accesses [fleXive] APIs.
  9. To get started, edit hello-flexive/war/src/main/webapp/index.xhtml and watch your changes being applied immediately by the Jetty server. Did I mention that Netbeans 6.5 natively supports Maven projects? More on that in a future post.
  10. You can just package your whole application using mvn package and deploy it on your Glassfish or JBoss server as well.

This project utilizes two major enhancements of the current development (3.1) version: support for the pure Java database H2 (in addition to MySQL), especially suited for development environments, and compatibility with the OpenEJB container. These improvements were necessary to allow us to run in a pure Java environment, without database or application server dependencies.

[Update 2009/09/14: set archetype version to 1.0-SNAPSHOT]

Blog at WordPress.com.