This tutorial explains how to use the Eclipse IDE and JBoss Tools with a Mavenized Seam project.
The shortcuts are listed here so we don't have to type the tedious file paths over and over again in this document.
${JBOSS_HOME}
- refers to Jboss installation directory, e.g.
${JBOSS_CONFIG}
- refers to the configuration directory e.g.
${JBOSS_DEPLOY}
- refers to the JBoss deploy directory, e.g.
${TRUNK}
- the project root directory, i.e. seam-maven-refimpl
${SEAM_REFIMPL}
- the directory where the reference project, i.e. seam-refimpl,
is installed on your computer
${SEAM_TUTORIAL}
- the directory where the tutorial project, i.e. seam-tutorial,
is installed on your computer
jboss-app.xml
dependent on the targeted JBoss
Application Server. This works fine with Maven 2.2.1, but fails in Maven 3. The latest
Maven3.0-beta1 does not evaluate external properties during the
ear:generate-application-xml
goal and you will get the following error message:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.4.2:generate-application-xml (default-generate-application-xml) on project mvn3-problem-ear: Failed to initialize JBoss configuration: Invalid JBoss configuration, version[${as.version}] is not supported. -> [Help 1]The bug is reported in JIRA: http://jira.codehaus.org/browse/MNG-2971.
jboss-4.2.3.GA.jdk6.zip
is the correct build for jdk-6.eclipse.ini
, see Eclipsepedia: Eclipse.ini.
Your eclipse.ini
should look something like this:
-vm C:/Program Files (x86)/Java/jdk1.6.0_17/bin/javaw.exe --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519 -startup plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar -product org.eclipse.epp.package.reporting.product --launcher.XXMaxPermSize 256M -showsplash org.eclipse.platform --launcher.XXMaxPermSize 256m -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms128m -Xmx512m
C:/dev/workspaces/seam
C:/dev/workspaces/seam/myproject
: You will not be able to run Maven Eclipse
goals from a command shell if your project is placed under the workspace directory; the
mvn eclipse:eclipse and mvn eclipse:clean
goals will fail to
execute. The issues are reported here:
http://jira.codehaus.org/browse/MECLIPSE-571, and here:
http://jira.codehaus.org/browse/MNG-2057.
So, be kind to yourself and create a project directory that is not on the same file path as your
workspace directory.Window>Preferences
and browse to the
Java>Installed JREs
section.
Maven>Installations
.
Click Add...
and select your Maven-2.2.1 home directory.
Use the JBoss deploy directory
radio button is checked.
This ends the steps needed to prepare the Eclipse workspace for Maven and JBoss Tools. You need to go trough this steps every time you create a new workspace.
m2eclipse provides three options for importing a Maven project into Eclipse including:
The options are described in detail in Maven: The Definitive Guide. In this tutorial we'll show how to use the first option.
m2eclipse can import a Maven project with an existing pom.xml. By pointing at the directory where a Maven project is located, m2eclipse detects all the Maven POMs in the project and provides a hierarchical list of them.
seam-refimpl
project
from svn to a directory of your choice, the ${SEAM_TUTORIAL}
directory. src/main/filters/filter-prod.properties
to
filter-dev.properties
and point the server to the correct deploy directory
(the as.deploy
property value should correspond with the configuration
directory you selected for the WTP server).
mvn install eclipse:eclipse
File>Import
to import the project:
Maven>Existing Maven Projects
and click Next.
env-dev
to the Profiles field
and click Finish.
Build errors for seam-tutorial-ear; org.apache.maven.lifecycle.LifecycleExecutionException:
Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.4.1:generate-application-xml
(default-generate-application-xml) on project seam-tutorial-ear: Failed to initialize JBoss
configuration
mvn install
from a command shell using Maven 3.
The bug is reported in JIRA: http://jira.codehaus.org/browse/MNG-2971.
ear/src/main/application
should be source folder.
src/main/application
target/seam-tutorial-ear-0.1-SNAPSHOT/META-INF
target/seam-tutorial-war-0.1-SNAPSHOT/WEB-INF
It should not be necessary to make any changes to the Project Facets, just verify that the facets are selected excactly as shown in the screenshots below. If they are not, then you should delete the project from Eclipse, Completly Remove Eclipse Spesific Settings From the Project and then import the project all over again.
install -Pexplode
and a Maven clean -Punexplode
run configurations:install
goal with the explode
profile is needed to do an initial
deploy to the server and also to fix some WTP issues (more on that later).
Below is the screenshot for the Maven install -Pexplode
run configuration. Also
create a run configuration for the Maven clean -Punexplode
goal. Remenber to use the
external Maven Runtime you configured for the workspace.Run As > Maven build
from the menu.
Running tests are trivial. Open a test class, right click in the editor and select
Run As > TestNG Test
.
The tests should go "green".
To have an effective development environment we need to automate the edit compile deploy cycle.
You can either use WTP to deploy your project or you can define a Maven builder that
hooks in to the process-classes
goal. For the latter, the seam-refimpl POMs has alredy
defined an explode
profile for the Maven process-classes goal. All you need to do is to
define a Maven builder that utilizes this profile on the process-classes
goal.
This section explains how to use WTP
to deploy your project.seam-tutorial-ear
project and click Finish.
seam-tutorial-ds.xml
file is the unfiltered version - not the one from ear/target/seam-tutorial-ear-0.1-SNAPSHOT
.
The problem is caused by this Eclipse bug:
Bug 247090 - Userlibraries
incorrectly deployed within EARs (and probably some m2eclipse/wtp/JBossTools bugs as well :)
mvn install -Pexplode
to fix the incorrect deploy.seam-tutorial-ds.xml the filtered version), META-INF/application.xml, META-INF/jboss-app.xml
and META-INF/MANIFEST.MF
are present.
mvn install -Pexplode
again.
As an alternative to WTP you can create a Maven builder that hooks into the
process-classes
goal. The Maven builder will then take care of the incremental
deployment. In combination with the mvn install -Pexplode
goal you will have a complete compile- build- deploy environment without WTP.
explode
profile on the process-classes
goal. The child poms will "inherit" this builder, so you only need to define the builder on the
parent project.
Note: Experiment with the Base directory
variable. If you use the
${project_loc}
variable then the builder will run only on the sub project that
contains the modified file - resulting in a faster build cycle.
mvn install -Pexplode
to do an initial deploy.Authenticator.java
. Modify the source, save and check
the console output:
Choose either to add the project to the WTP server or define a Maven builder.
JBoss Tools is a perfect match for Seam devolpers using Maven and the Elipse IDE. It helps you with a a lot of tasks you otherwise would have used hours and days to complete. The Tools is not essential for developing a Mavenized Seam application, but it provides a collection of tools that help you generate code and develop in an incremental manner. The JBossTools project hosts a variety of standalone Eclipse plug-ins that support Java EE development. You can use the tools to do reverse engineering : If you have an existing database then the Tools can generate a full CRUD application with entities, Seam framework classes (home- and list classes) and a user interface with navigation and drilldown. If you use the Tools to create an entity class then the Tools will automatically generate the corresponding Seam framework classes and userinterface (list and a detail page).
JBoss tools is a Eclipse feature, that can be enabled on a project by adding some configuration (JSF and Seam facets, the SeamBuilder and SeamNature) to the Eclipse project. JBoss Tools will manage two projects: the WAR and the EJB project, but the WAR project will be the main source of configuration. By adding the necessary items to the maven-eclipse-plugin configuration for this project and also adding a special Seam configuration file to the .settings directory, JBoss tools will recognize the project correctly. For some reason, JBoss tools also stores some configuration in the workspace configuration. This can not be configured from the Maven Archetype and thus the JBoss Tools configuration is not complete. Because of this, the link between the WAR and EJB project will not be found by JBoss Tools from the EJB project. When a new Seam Artifact (Action, Entity, Form or Conversation) is added from the EJB project context menu, the configurations made in the WAR project are not picked up. When adding from the WAR project they are picked up and some sources will also be written in the EJB projects, as required (source: Configuring a Seam EJB project for development with Maven and JBoss Tools ).
If you really want to learn the mecanisms behind Seam, then it is definitively worth the effort setting up the tools. Play with the tools and study the code that the various tools generates.
Unpack JBoss Seam to a directory of your
choice, e.g. C:/ide/libs/jboss-seam-2.2.0.GA
. Select Window > Prefereneces
and follow the screenshots.
JBoss Tools will manage two projects: the WAR and the EJB project. The WAR project will be the main source of configuration, so we'll start with the WAR.
Keep a copy of your project, preferably in svn, before you start configuring the tools.
war/src/main/webapp/home.xhtml
and ignore the waring about
Missing Natures. Do not use the Add JSF Capabilities wizard as suggested in the dialog - it
generates code and a lot of jar files in WEB-INF/lib which is not needed by a Maven project.
In this section we'll play with the tools.
New>Seam Entity
MyEntity
, and click
Finish.MyEntity.java
MyEntityHome.java
MyEntityList.java
myEntityList.xhtml
myEntity.xhtml
xhtml
files to the webapp/view
directory, but the code generator does not take this into
account. The links in the generated xhtml
code "assumes" that the code is generated
to the webapp
directory. So, to finish up, we fix this flaw by making some small changes
to the genereated xhtml
code. Also add a link to myEntityList.xhtml
in
menu.xhtml
(see the blue text).
myEntityList.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" template="/layout/template.xhtml"> <ui:define name="body"> <rich:panel> <f:facet name="header">myEntityList</f:facet> <div class="results"> <h:outputText value="No myEntity exists" rendered="#{empty myEntityList.resultList}"/> <h:dataTable id="myEntityList" var="myEntity" value="#{myEntityList.resultList}" rendered="#{not empty myEntityList.resultList}"> <h:column> <f:facet name="header">Id</f:facet> #{myEntity.id} </h:column> <h:column> <f:facet name="header">Name</f:facet> <s:link id="myEntity" value="#{myEntity.name}" propagation="none" view="/view/myEntity.xhtml"> <f:param name="myEntityId" value="#{myEntity.id}"/> </s:link> </h:column> </h:dataTable> </div> </rich:panel> <div class="actionButtons"> <s:button id="done" value="Create myEntity" view="/view/myEntity.xhtml"/> </div> </ui:define> </ui:composition>
myEntity.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" template="/layout/template.xhtml"> <ui:define name="body"> <h:form id="myEntityForm"> <rich:panel> <f:facet name="header">myEntity</f:facet> <s:decorate id="nameField" template="/layout/edit.xhtml"> <ui:define name="label">Name</ui:define> <h:inputText id="name" required="true" value="#{myEntityHome.instance.name}"/> </s:decorate> <div style="clear:both"/> </rich:panel> <div class="actionButtons"> <h:commandButton id="save" value="Save" action="#{myEntityHome.persist}" rendered="#{!myEntityHome.managed}"/> <h:commandButton id="update" value="Save" action="#{myEntityHome.update}" rendered="#{myEntityHome.managed}"/> <h:commandButton id="delete" value="Delete" action="#{myEntityHome.remove}" immediate="true" rendered="#{myEntityHome.managed}"/> <s:button propagation="end" id="cancel" value="Cancel" view="/view/myEntityList.xhtml"/> </div> </h:form> </ui:define> </ui:composition>
menu.xhtml
<rich:toolBar xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:rich="http://richfaces.org/rich"> <rich:toolBarGroup> <h:outputText value="#{projectName}:"/> <s:link view="/home.xhtml" value="Home" propagation="none"/> </rich:toolBarGroup> <!-- @newMenuItem@ --> <s:link view="/view/example/userList.xhtml" value="User List" includePageParams="false" propagation="none"/> <s:link view="/view/myEntityList.xhtml" value="myEntity List" includePageParams="false" propagation="none"/> <rich:toolBarGroup location="right"> <h:outputText value="signed in as: #{identity.username}" rendered="#{identity.loggedIn}"/> <s:link view="/login.xhtml" value="Login" rendered="#{not identity.loggedIn}" propagation="none"/> <s:link view="/home.xhtml" action="#{identity.logout}" value="Logout" rendered="#{identity.loggedIn}" propagation="none"/> </rich:toolBarGroup> </rich:toolBar>
mvn install -Pexplode
to do an initial
deploy. Start server and point your browser to
http://localhost:8080/seam-tutorial/
Well, the tutorial is not done in 60 seconds, but the revrese engineering is.
We will re-use the project from the previous section, so complete that tutorial first.
open18-initial-schema-mysql.sql
and
open18-initial-seed-data-mysql.sql
from svn,
http://seam-maven-refimpl.googlecode.com/svn/trunk/samples/seaminaction/etc/schema/.
open18initial_db
.
open18-initial-schema-mysql.sql
and click execute.
open18-initial-seed-data-mysql.sql
and click execute.
Add Configuration...
filter-dev.properties
.
... # Datasource ds =mysql ds.jndi.name =${app}Database ds.database.name =open18initial_db ds.server.name =localhost:3306 ds.driver.class =com.mysql.jdbc.Driver ds.connection.url =jdbc:mysql://${ds.server.name}/${ds.database.name}?characterEncoding=UTF-8 ds.user.name =root ds.password = ds.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect ds.xml =${app.context}-ds.xml # Persistence unit pu.name =${app}-unit pu.jta.data.source =java:/${ds.jndi.name} pu.hibernate.dialect =${ds.hibernate.dialect} pu.hibernate.hbm2ddl.auto =update pu.hibernate.show_sql =false pu.hibernate.default_batch_fetch_size =16 pu.hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup pu.jboss.entity.manager.factory.jndi.name =java:/${app.context}EntityManagerFactory ...
seam-tutorial
project.
seam-tutorial-ejb/src/test/java
; delete package no.knowit.seam.example.action
seam-tutorial-ejb/src/main/java
; delete packages org.domain.seamtutorial.session
,
org.domain.seamtutorial.entity
, no.knowit.seam.example.action
and
no.knowit.seam.example.model
seam-tutorial-war
; delete the webapp/view
directory
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId><configuration><suiteXmlFiles><suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile></suiteXmlFiles></configuration></plugin>
webapp/layout/menu.xhtml
to:
<rich:toolBar xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:rich="http://richfaces.org/rich"> <rich:toolBarGroup> <h:outputText value="#{projectName}:"/> <s:link id="menuHomeId" view="/home.xhtml" value="Home" propagation="none"/> </rich:toolBarGroup> <!-- @newMenuItem@ --> <rich:toolBarGroup location="right"> <h:outputText id="menuWelcomeId" value="signed in as: #{credentials.username}" rendered="#{identity.loggedIn}" /> <s:link id="menuLoginId" view="/login.xhtml" value="Login" rendered="#{not identity.loggedIn}" propagation="none" /> <s:link id="menuLogoutId" view="/home.xhtml" action="#{identity.logout}" value="Logout" rendered="#{identity.loggedIn}" propagation="none" /> </rich:toolBarGroup> </rich:toolBar>
/seam-tutorial-war/src/main/webapp
so that xhtml files are generated to the webapp directory (so we don't need to modify generated
xhtml code as we did in the previous tutorial).
mvn clean
and mvn install
on the
parent project.
New>Seam Generate Entities
mvn install -Pexplode
, start server and point your browser to
http://localhost:8080/seam-tutorial/
TeeList
page fails to load. org.domain.seamtutorial.session.TeeList
@Override protected String getCountEjbql() { String before = super.getCountEjbql(); String after = before.replace("select count(tee) ", "select count(*) "); return(after); }Also check comments i code here.
File>Import
to import the trunk:
Checkout Projects from SVN
and click Next.
Check out as a project in the workspace
and click
Next.
Use default workspace location
checkbox and
browse to the directory where you want to check out the trunk.
The m2eclipse
plugin seems to be a bit unpredictable when it comes to downloading
sourcecode and javadocs for the projects dependencies. If you find that source code and javadocs are
missing for some dependencies, then try this:
${SEAM_TUTORIAL}
, using a command shell and
execute:
mvn eclipse:eclipse -DdownloadSources=true
-DdownloadJavadocs=true
If you find yourself in a situation where your Eclipse project has reached a limbo, then you are faced with two options: Delete the project from your local file system (and then svn:update), or you could try to clean up the mess caused by Eclipse (and you?).
Steps required to clean up Eclipse mess:
${SEAM_TUTORIAL}
directory using
a command shell and execute maven commands:
mvn clean -Penv-dev,unexplode
mvn eclipse:clean
mvn eclipse:clean
goal delets most of the Eclipse spesific project files, but
not all of them. We need to clean up the remaining dot files ourselves:
Browse all project folders refered in the <modules>
section of the parent pom
and delete all dot files that belongs to Eclipse, e.g.
mvn install -Penv-dev
mvn eclipse:eclipse
.project
, .classpath
and WTP files that now makes the project a valid Eclipse project.
See: access restriction problems
See: Build path contains duplicate entry: 'org.eclipse.jst.j2ee.internal.module.container'
Do not add Maven projects under your workspace directory. There are some issues regarding use of the
m2eclipse plugin when projects are placed under the workspace directory, e.g.
C:/dev/ide/workspaces/eclipse-3.4/myproject
: You will not be
able to run Maven Eclipse goals from a command shell if your project is placed under the workspace
directory; the mvn eclipse:eclipse and mvn eclipse:clean
goals will
fail to execute. The issues are reported here:
http://jira.codehaus.org/browse/MECLIPSE-571, and here:
http://jira.codehaus.org/browse/MNG-2057.
So, be kind to yourself and create a project directory that is not on the same file path as the
workspace directory, e.g. C:/dev/projects
The WAR pom must list all Java modules you want to browse into:
<dependencies> <!-- project --> <!-- For Eclipse and JBoss Tools: List all modules you are interested to browse (ctrl+click) into from xhtml pages --> <dependency> <groupId>${project.groupId}</groupId> <artifactId>${app.context}-ejb</artifactId> <type>ejb</type> <scope>provided</scope> </dependency> <!-- seam --> <dependency> <groupId>org.jboss.seam</groupId> <artifactId>jboss-seam-ui</artifactId> </dependency> . . </dependencies>
It only works partially! It seems that everything except for the visual editors (VPE) works fine. You will see the following message in the visual editor: "The VPE editor can't be run because your system environment needs to be changed slightly. Find out more". The link points to a page with no information regarding how to fix this for Vista64 with Jdk-6 64 bit and Eclipse-3.4 64 bit. You will also find that you are not able to browse into java code from the visual editor, which for me is the most essential feature of the VPE. The only workaround I have found so far is to download and install 32 bit versions of Jdk-6 and Eclipse-3.4 and install the required plugins in the Eclipse-3.5 32 bit environment. The visual editors works as expected with the 32 bit configuration.
After installation of Jdk-6 32 bit and Eclipse-3.4 32 bit, ensure that Eclipse uses the "correct"
jdk. Open the eclipse.ini
file and add path to the 32 bit Jdk version as emphasized in
text below:
-vm C:/Program Files (x86)/Java/jdk1.6.0_16/bin -showsplash org.eclipse.platform --launcher.XXMaxPermSize 512M -framework plugins\org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms128m -Xmx512m