Pierwsze kroki z JBoss Seam i Apache Geronimo
Z Jacek Laskowski - Wiki Projektanta Java EE
Kilka dni temu pisałem o aplikacji opartej o JSF (JavaServer Faces), w której potrzebowałem skorzystać ze znaczników JSP projektu jpivot. Właśnie przed konfiguracją mechanizmu utrwalania danych opartych o Spring Framework i JPA (Java Persistence API) myślałem o rozwiązaniu ala Ruby on Rails (RoR), w którym podałbym podstawowe dane aplikacji, a większość z niej utworzona byłaby automatycznie. Moja aplikacja nie będzie aplikacją CRUD (Create/Read/Update/Delete) , ale jej zręby przydałyby mi się na starcie. I tak sobie rozważałem, jakby tu ubrać temat w jakiś projekt (potencjalnie rozwijany przez społeczność polskich JUGów), aż tu przypomniałem sobie o...JBoss Seam! Nie wiem jak mogłem o nim zapomnieć! Skoro potrzebuję szkieletu ala RoR, JSF, JPA i biblioteki kontrolek JSF w postaci Apache MyFaces Trinidad czy podobnie, to właśnie JBoss Seam zdaje się być idealnym rozwiązaniem. To się nazywa znaleźć rozwiązanie na miarę wymagań. Nie należę do znawców tematu JBoss Seam, więc tym bardziej kręci mnie popróbowanie się z nim.
Lektura strony domowej projektu JBoss Seam - http://seamframework.org - nie pozostawia złudzeń wyboru szkieletu aplikacyjnego:
Seam is a powerful open source development platform for building rich Internet applications in Java. Seam integrates technologies such as Asynchronous JavaScript and XML (AJAX), JavaServer Faces (JSF), Java Persistence (JPA), Enterprise Java Beans (EJB 3.0) and Business Process Management (BPM) into a unified full-stack solution, complete with sophisticated tooling.
To jest dokładnie to, czego potrzebowałem do zbudowania mojej nowej aplikacji.
Zaczynam od instalacji JBoss Seam 2.0.2.SP1. Jedna z uwag, która od razu widoczna jest dla nowych użytkowników - większość odnośników wskazuje na starszą wersję JBoss Seam 2.0.1, podczas gdy mamy już 2.0.2.GA i 2.0.2.SP1.
Docelowa konfiguracja obejmuje uruchomienie JBoss Seam w ramach serwera aplikacyjnego Apache Geronimo 2.1.1.
Zaczynam od lektury Chapter 2. Getting started with Seam, using seam-gen. "Dlaczego od razu z seam-gen?" możesz zapytać. Za pomocą seam-gen mam możliwość zbudowania kompletnej aplikacji webowej opartej o Seam, podobnie jak osoby pracujące z szkieletami webowymi ala RoR.
Nie zamierzam wykorzystać serwera JBoss AS, więc krok z seam setup wykonam wyłącznie pro forma.
jlaskowski@work /cygdrive/c/apps/jboss-seam
$ ./seam setup
Buildfile: build.xml
init:
setup:
[echo] Welcome to seam-gen :-)
[input] Enter your Java project workspace (the directory that contains your Seam projects) [C:/Projects] [C:/Projects]
c:/.eclipse-seam
[input] Enter your JBoss home directory [C:/Program Files/jboss-4.2.2.GA] [C:/Program Files/jboss-4.2.2.GA]
[input] Enter the project name [myproject] [myproject]
seam-rozpoczynamy
[echo] Accepted project name as: seam_rozpoczynamy
[input] Do you want to use ICEFaces instead of RichFaces [n] (y, [n])
[input] skipping input as property icefaces.home.new has already been set.
[input] Select a RichFaces skin [blueSky] ([blueSky], classic, ruby, wine, deepMarine, emeraldTown, sakura, DEFAULT)
[input] Is this project deployed as an EAR (with EJB components) or a WAR (with no EJB support) [ear] ([ear], war)
[input] Enter the Java package name for your session beans [com.mydomain.seam_rozpoczynamy] [com.mydomain.seam_rozpoczynamy]
pl.jaceklaskowski.seam
[input] Enter the Java package name for your entity beans [pl.jaceklaskowski.seam] [pl.jaceklaskowski.seam]
pl.jaceklaskowski.seam.model
[input] Enter the Java package name for your test cases [pl.jaceklaskowski.seam.test] [pl.jaceklaskowski.seam.test]
[input] What kind of database are you using? [hsql] ([hsql], mysql, oracle, postgres, mssql, db2, sybase, enterprisedb, h2)
[input] Enter the Hibernate dialect for your database [org.hibernate.dialect.HSQLDialect] [org.hibernate.dialect.HSQLDialect]
[input] Enter the filesystem path to the JDBC driver jar [../lib/hsqldb.jar] [../lib/hsqldb.jar]
[input] Enter JDBC driver class for your database [org.hsqldb.jdbcDriver] [org.hsqldb.jdbcDriver]
[input] Enter the JDBC URL for your database [jdbc:hsqldb:.] [jdbc:hsqldb:.]
[input] Enter database username [sa] [sa]
[input] Enter database password [] []
[input] Enter the database schema name (it is OK to leave this blank) [] []
[input] Enter the database catalog name (it is OK to leave this blank) [] []
[input] Are you working with tables that already exist in the database? [n] (y, [n])
[input] Do you want to drop and recreate the database tables and data in import.sql each time you deploy? [n] (y, [n])
[propertyfile] Creating new property file: c:\apps\jboss-seam\seam-gen\build.properties
[echo] Installing JDBC driver jar to JBoss server
[copy] Copying 1 file to C:\Program Files\jboss-4.2.2.GA\server\default\lib
[echo] Type 'seam create-project' to create the new project
BUILD SUCCESSFUL
Total time: 5 minutes 1 second
Dokumentacja wspomina o poleceniu seam new-project, mimo że polecenie seam zakończyło działanie z Type 'seam create-project' to create the new project. Zaczyna się wspaniale!
jlaskowski@work /cygdrive/c/apps/jboss-seam
$ ./seam create-project
Buildfile: build.xml
init:
init-properties:
[echo] C:/Program Files/jboss-4.2.2.GA
validate-workspace:
validate-project:
icefaces-staging-copy:
initcopy:
initpoms:
[echo] Setting up dependencies
[mkdir] Created dir: c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[artifact:install] Error reading settings file '\cygdrive\c\apps\apache-maven\conf\settings.xml' - ignoring.
Error was: \cygdrive\c\apps\apache-maven\conf\settings.xml (The system cannot find the path specified)
[artifact:install] [INFO] Installing c:\apps\jboss-seam\classes\poms\root.pom to
C:\Documents and Settings\jlaskowski\.m2\repository\org\jboss\seam\root\2.0.2.SP1\root-2.0.2.SP1.pom
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[artifact:install] Error reading settings file '\cygdrive\c\apps\apache-maven\conf\settings.xml' - ignoring.
Error was: \cygdrive\c\apps\apache-maven\conf\settings.xml (The system cannot find the path specified)
[pom] Error reading settings file '\cygdrive\c\apps\apache-maven\conf\settings.xml' - ignoring.
Error was: \cygdrive\c\apps\apache-maven\conf\settings.xml (The system cannot find the path specified)
[artifact:install] Downloading: org/jboss/seam/root/2.0.2.SP1/root-2.0.2.SP1.pom from central
[pom] Error downloading parent pom org.jboss.seam:root::2.0.2.SP1: Missing:
[pom] ----------
[pom] 1) org.jboss.seam:root:pom:2.0.2.SP1
[pom] Path to dependency:
[pom] 1) unspecified:unspecified:jar:0.0
[pom] 2) org.jboss.seam:root:pom:2.0.2.SP1
[pom]
[pom] ----------
[pom] 1 required artifact is missing.
[pom]
[pom] for artifact:
[pom] unspecified:unspecified:jar:0.0
[pom]
[pom] from the specified remote repositories:
[pom] central (http://repo1.maven.org/maven2)
[artifact:install] [INFO] Installing c:\apps\jboss-seam\classes\poms\parent.pom to
C:\Documents and Settings\jlaskowski\.m2\repository\org\jboss\seam\parent\2.0.2.SP1\parent-2.0.2.SP1.pom
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
[copy] Copying 1 file to c:\apps\jboss-seam\classes\poms
copyseam:
copyseamdependencies:
copyjbossembedded:
copy-icefaces-home:
copy-icefaces-maven:
copy-lib:
[echo] Copying Seam and depdencies to the c:/.eclipse-seam/seam_rozpoczynamy/lib directory...
[copy] Copying 101 files to c:\.eclipse-seam\seam_rozpoczynamy\lib
[copy] Copied 4 empty directories to 1 empty directory under c:\.eclipse-seam\seam_rozpoczynamy\lib
[echo] Copying JBoss Embedded configuration to the c:/.eclipse-seam/seam_rozpoczynamy/bootstrap directory...
[copy] Copying 30 files to c:\.eclipse-seam\seam_rozpoczynamy\bootstrap
file-copy-war:
file-copy-ear:
[echo] Copying resources needed for EAR deployment to the c:/.eclipse-seam/seam_rozpoczynamy/resources directory...
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\resources\WEB-INF
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy
[copy] Copying 6 files to c:\.eclipse-seam\seam_rozpoczynamy\resources
setup-filters:
file-copy:
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy
[copy] Copying 11 files to c:\.eclipse-seam\seam_rozpoczynamy\resources
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\resources
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\.settings
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\resources
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\resources
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\resources
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\resources
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\resources
[copy] Copying 10 files to c:\.eclipse-seam\seam_rozpoczynamy\view
[copy] Copying 2 files to c:\.eclipse-seam\seam_rozpoczynamy\view
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\src\action\pl\jaceklaskowski\seam
[copy] Copying 6 files to c:\.eclipse-seam\seam_rozpoczynamy
[mkdir] Created dir: c:\.eclipse-seam\seam_rozpoczynamy\src\model
[mkdir] Created dir: c:\.eclipse-seam\seam_rozpoczynamy\src\test
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\src\test
[mkdir] Created dir: c:\.eclipse-seam\seam_rozpoczynamy\nbproject
[copy] Copying 3 files to c:\.eclipse-seam\seam_rozpoczynamy\nbproject
create-project:
[echo] A new Seam project named 'seam_rozpoczynamy' was created in the c:/.eclipse-seam directory
[echo] Type 'seam explode' and go to http://localhost:8080/seam_rozpoczynamy
[echo] Eclipse Users: Add the project into Eclipse using File > New > Project and select General > Project (not Java Project)
[echo] NetBeans Users: Open the project in NetBeans
BUILD SUCCESSFUL
Total time: 12 seconds
Pracuję na Cygwin i zmienna MAVEN_HOME ustawiona jest na /cygdrive/c/apps/apache-maven.
jlaskowski@work /cygdrive/c/apps/jboss-seam $ echo $MAVEN_HOME /cygdrive/c/apps/apache-maven
Stąd te komunikaty o /cygdrive/c/apps/apache-maven, którego Seam nie rozpoznaje jako poprawny katalog.
Ciekawostką jest podsumowanie utworzenia projektu przez seam:
[echo] A new Seam project named 'seam_rozpoczynamy' was created in the c:/.eclipse-seam directory
[echo] Type 'seam explode' and go to http://localhost:8080/seam_rozpoczynamy
[echo] Eclipse Users: Add the project into Eclipse using File > New > Project and select General > Project (not Java Project)
[echo] NetBeans Users: Open the project in NetBeans
Jest, więc ukłon w stronę użytkowników Eclipse i NetBeans. A co z pozostałymi?! Sądzę, że IntelliJ IDEA jest również szeroko używanym narzędziem i Seam mógłby chociaż nadmienić dodatkowo o IDEA.
jlaskowski@work /cygdrive/c/apps/jboss-seam
$ ./seam explode
Buildfile: build.xml
init:
init-properties:
[echo] C:/Program Files/jboss-4.2.2.GA
validate-workspace:
validate-project:
explode:
[echo] Deploying project 'seam_rozpoczynamy' to JBoss as an exploded directory
init:
[mkdir] Created dir: c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar
[mkdir] Created dir: c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.ear
[mkdir] Created dir: c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.war
[mkdir] Created dir: c:\.eclipse-seam\seam_rozpoczynamy\dist
compile:
[javac] Compiling 1 source file to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar
BUILD FAILED
c:\apps\jboss-seam\seam-gen\build.xml:1213: The following error occurred while executing this line:
c:\.eclipse-seam\seam_rozpoczynamy\build.xml:60: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "c:\apps\java5\jre"
Total time: 0 seconds
jlaskowski@work /cygdrive/c/apps/jboss-seam
$ echo $JAVA_HOME
/cygdrive/c/apps/java5
Kolejny raz praca z Seam w środowisku Cygwin daje mi się we znaki i najwyraźniej skrypt seam nie radzi sobie dobrze z tym środowiskiem.
jlaskowski@work /cygdrive/c/apps/jboss-seam
$ JAVA_HOME="c:/apps/java5" ./seam explode
Buildfile: build.xml
init:
init-properties:
[echo] C:/Program Files/jboss-4.2.2.GA
validate-workspace:
validate-project:
explode:
[echo] Deploying project 'seam_rozpoczynamy' to JBoss as an exploded directory
init:
compile:
[javac] Compiling 1 source file to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar
copyclasses:
jar:
[copy] Copying 2 files to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar\META-INF
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar\META-INF
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar
war:
[copy] Copying 12 files to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.war
[copy] Copying 4 files to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.war\WEB-INF
[copy] Copying 11 files to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.war\WEB-INF\lib
[copy] Copying 5 files to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.war\WEB-INF\classes
ear:
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.ear
[copy] Copying 9 files to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.ear\lib
[copy] Copying 2 files to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.ear\META-INF
datasource:
[copy] Copying 1 file to C:\Program Files\jboss-4.2.2.GA\server\default\deploy
explode:
[copy] Copying 6 files to C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear\seam_rozpoczynamy.jar
[copy] Copying 32 files to C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear\seam_rozpoczynamy.war
[copy] Copying 12 files to C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear
BUILD SUCCESSFUL
Total time: 3 seconds
Skoro nie mam JBAS, a potrzebne mi jest środowisko uruchomieniowe dla utworzonej aplikacji, skorzystam z Apache Geronimo (już dawno o nim nie wspominałem i trochę mi się za nim stęskniło).
Uruchamiam Geronimo poleceniem ./bin/geronimo.sh run -vv (opcja -vv nie jest konieczna, więc można ją opuścić). Po pełnym uruchomieniu, kiedy pojawi się Geronimo startup complete podchodzę do rozmieszczenia aplikacji seam_rozpoczynamy.ear (z katalogu C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear - trzeba mi było uruchomić seam setup z krótszą ścieżką do JBAS, której instalacji skrypt seam nie sprawdza).
jlaskowski@work /cygdrive/c/geronimo $ ./bin/deploy.sh -u system -p manager deploy "C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear" Using GERONIMO_BASE: c:\geronimo Using GERONIMO_HOME: c:\geronimo Using GERONIMO_TMPDIR: var\temp Using JRE_HOME: c:\apps\java5\jre Error: Unable to distribute seam_rozpoczynamy.ear: web.xml for web app seam_rozpoczynamy.war includes security elements but Geronimo deployment plan is not provided or does not contain <security-realm-name> element necessary to configure security accordingly.
Skorzystam z pomocy dokumentacji Geronimo - Running JBoss Seam 2.0.0.GA on Geronimo 2.1 do "skomponowania" planu. Potrzebne jest również uzupełnienie aplikacji o pliki jar Hibernate, których Geronimo nie posiada, a który jest domyślnym dostawcą JPA w utworzonej aplikacji przez skrypt seam.
Zmieniam deployed-jars-ear.list projektu o dodanie następujących bibliotek:
concurrent.jar dom4j.jar hibernate.jar hibernate-annotations.jar hibernate-commons-annotations.jar hibernate-entitymanager.jar hibernate-validator.jar javassist.jar jboss-common-core.jar
Ponowne zbudowanie aplikacji poleceniem JAVA_HOME="c:/apps/java5" ./seam explode.
jlaskowski@work /cygdrive/c/geronimo
$ JAVA_HOME="c:/apps/java5" c:/apps/jboss-seam/seam explode
Buildfile: build.xml
init:
init-properties:
[echo] C:/Program Files/jboss-4.2.2.GA
validate-workspace:
validate-project:
explode:
[echo] Deploying project 'seam_rozpoczynamy' to JBoss as an exploded directory
init:
compile:
copyclasses:
jar:
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar\META-INF
[copy] Copying 1 file to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.jar
war:
ear:
[copy] Copying 3 files to c:\.eclipse-seam\seam_rozpoczynamy\exploded-archives\seam_rozpoczynamy.ear\lib
datasource:
explode:
[copy] Copying 2 files to C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear\seam_rozpoczynamy.jar
[copy] Copying 2 files to C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear
BUILD SUCCESSFUL
Total time: 0 seconds
Błędne uruchomienie aplikacji powoduje pozostanie "śmieci" w repozytorium Geronimo, które czyszczę przez skasowanie katalogu $GERONIMO_HOME/repository/pl.
jlaskowski@work /cygdrive/c/geronimo $ rm -rf repository/pl
Jak można przeczytać w zgłoszeniu Add GeronimoTransactionManagerLookup wsparcie dla JTA w środowisku Apache Geronimo wciąż pozostaje nierozwiązane bezpośrednio przez Hibernate, więc konieczna jest interwencja polegająca na instalacji klasy wspierającej Hibernate do pozyskania dostępu do monitora transakcji specyficznego dla Geronimo. Próba uruchomienia aplikacji bez niego kończy się komunikatem błędu:
Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:329)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
... 73 more
Zgodnie z sekcją Hibernate Transaction Manager Lookup class for Geronimo w Running JBoss Seam 2.0.0.GA on Geronimo 2.1 wykonuje zbudowanie projektu dla wsparcia Hibernate do pracy w środowisku Geronimo i rozmieszczam aplikację poleceniem ./bin/deploy.sh -u system -p manager deploy "C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear" seam_rozpoczynamy-plan.xml, gdzie seam_rozpoczynamy-plan.xml to plik-plan z konfiguracją aplikacji dla Geronimo.
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-2.0">
<environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
<moduleId>
<groupId>pl.jaceklaskowski.seam</groupId>
<artifactId>seam_rozpoczynamy</artifactId>
<version>1.0</version>
<type>ear</type>
</moduleId>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.hibernate.transaction</groupId>
<artifactId>geronimo-hibernate-transaction-manager-lookup</artifactId>
<type>jar</type>
</dependency>
</dependencies>
</environment>
<module>
<web>seam_rozpoczynamy.war</web>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
<environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
<moduleId>
<groupId>pl.jaceklaskowski.seam</groupId>
<artifactId>seam_rozpoczynamy</artifactId>
<version>1.0</version>
<type>war</type>
</moduleId>
</environment>
<context-root>/seam_rozpoczynamy</context-root>
<security-realm-name>seam_rozpoczynamy-realm</security-realm-name>
<security>
<default-principal realm-name="seam_rozpoczynamy-realm">
<principal name="anonymous" class="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal" />
</default-principal>
<role-mappings>
<role role-name="admin">
<realm realm-name="seam_rozpoczynamy-realm">
<principal name="AdminGroup" class="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal" />
</realm>
<principal name="system" class="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal" />
</role>
</role-mappings>
</security>
</web-app>
</module>
<module>
<ejb>seam_rozpoczynamy.jar</ejb>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
<environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
<moduleId>
<groupId>pl.jaceklaskowski.seam</groupId>
<artifactId>seam_rozpoczynamy</artifactId>
<version>1.0</version>
<type>jar</type>
</moduleId>
</environment>
<!-- overrides what's in the module's persistence.xml -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="seam_rozpoczynamy">
<jta-data-source>jdbc/seam_rozpoczynamyDatasource</jta-data-source>
<properties>
<property name="hibernate.transaction.manager_lookup_class" value="org.apache.geronimo.hibernate.transaction.GeronimoTransactionManagerLookup" />
<property name="jboss.entity.manager.factory.jndi.name" value="java:/seam_rozpoczynamyEntityManagerFactory" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
</persistence>
</openejb-jar>
</module>
<ext-module>
<connector>seam_rozpoczynamy-dbpool</connector>
<external-path xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
<dep:groupId>org.tranql</dep:groupId>
<dep:artifactId>tranql-connector-derby-embed-xa</dep:artifactId>
<dep:type>rar</dep:type>
</external-path>
<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
<environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
<moduleId>
<groupId>pl.jaceklaskowski.seam</groupId>
<artifactId>seam_rozpoczynamy</artifactId>
<version>1.0</version>
<type>rar</type>
</moduleId>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.configs</groupId>
<artifactId>system-database</artifactId>
<type>car</type>
</dependency>
</dependencies>
</environment>
<resourceadapter>
<outbound-resourceadapter>
<connection-definition>
<connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
<connectiondefinition-instance>
<name>jdbc/seam_rozpoczynamyDatasource</name>
<config-property-setting name="DatabaseName">SystemDatabase</config-property-setting>
<connectionmanager>
<local-transaction />
<single-pool>
<max-size>100</max-size>
<blocking-timeout-milliseconds>5000</blocking-timeout-milliseconds>
<select-one-assume-match />
</single-pool>
</connectionmanager>
</connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
</connector>
</ext-module>
</application>
Poprawna instalacja aplikacji kończy się następującymi komunikatami na konsoli Geronimo:
00:03:37,687 INFO [Version] Hibernate Annotations 3.3.0.GA
00:03:37,734 INFO [Environment] Hibernate 3.2.4.sp1
00:03:37,812 INFO [Environment] hibernate.properties not found
00:03:37,812 INFO [Environment] Bytecode provider name : cglib
00:03:37,828 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
00:03:38,125 INFO [Version] Hibernate EntityManager 3.3.1.GA
00:03:38,234 INFO [Ejb3Configuration] Processing PersistenceUnitInfo [
name: seam_rozpoczynamy
...]
00:03:38,703 INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
00:03:38,734 INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
00:03:39,234 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
00:03:39,250 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
00:03:39,250 INFO [SettingsFactory] RDBMS: Apache Derby, version: 10.2.2.0 - (485682)
00:03:39,250 INFO [SettingsFactory] JDBC driver: Apache Derby Embedded JDBC Driver, version: 10.2.2.0 - (485682)
00:03:39,328 INFO [Dialect] Using dialect: org.hibernate.dialect.HSQLDialect
...
00:03:40,078 INFO [ServletContextListener] Welcome to Seam 2.0.2.SP1
Na konsoli, gdzie uruchomiłem polecenie ./bin/deploy.sh wypisane są zainstalowane moduły aplikacji:
jlaskowski@work /cygdrive/c/geronimo
$ ./bin/deploy.sh -u system -p manager deploy "C:\Program Files\jboss-4.2.2.GA\server\default\deploy\seam_rozpoczynamy.ear" seam_rozpoczynamy-plan.xml
Using GERONIMO_BASE: c:\geronimo
Using GERONIMO_HOME: c:\geronimo
Using GERONIMO_TMPDIR: var\temp
Using JRE_HOME: c:\apps\java5\jre
Deployed pl.jaceklaskowski.seam/seam_rozpoczynamy/1.0/ear
`-> seam_rozpoczynamy.war @ /seam_rozpoczynamy
`-> seam_rozpoczynamy.jar
`-> jboss-seam.jar
`-> seam_rozpoczynamy-dbpool
Potencjalnie można jeszcze napotkać błąd związany z wyższą wersją Javy w Eclipse niż wykorzystana do uruchomienia Geronimo. Należy sprawdzić ustawienia Eclipse w Properties > Java Compiler > Compiler compliance level, tak aby wartość była 1.5.
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.apache.geronimo.kernel.classloader.JarFileClassLoader.access$200(JarFileClassLoader.java:52)
at org.apache.geronimo.kernel.classloader.JarFileClassLoader$6.run(JarFileClassLoader.java:308)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.geronimo.kernel.classloader.JarFileClassLoader.findClass(JarFileClassLoader.java:260)
at org.apache.geronimo.kernel.config.MultiParentClassLoader.loadClassInternal(MultiParentClassLoader.java:470)
at org.apache.geronimo.kernel.config.MultiParentClassLoader.checkParents(MultiParentClassLoader.java:498)
at org.apache.geronimo.kernel.config.MultiParentClassLoader.loadOptimizedClass(MultiParentClassLoader.java:407)
at org.apache.geronimo.kernel.config.MultiParentClassLoader.loadClass(MultiParentClassLoader.java:278)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
Uruchomienie aplikacji w przeglądarce z adresem http://localhost:8080/seam_rozpoczynamy kończy się wyświetleniem strony home.seam.

