5.2. Setting up a new project
Configure seam-gen for your environment:
cd jboss-seam-2.3.5.Final-redhat-1 ./seam setup
A prompt appears for the required information:
~/workspace/jboss-seam$ ./seam setup
Buildfile: build.xml
init:
setup:
[echo] Welcome to seam-gen :-)
[input] Enter your project workspace (the directory that contains your Seam projects) [C:/Projects] [C:/Projects] /Users/pmuir/workspace
[input] Enter your JBoss AS home directory [C:/Program Files/jboss-as-7.1.1.Final] [C:/Program Files/jboss-as-7.1.1.Final]/Applications/jboss-as-7.1.1.Final
[input] Enter the project name [myproject] [myproject] helloworld
[echo] Accepted project name as: helloworld
[input] Select a RichFaces skin [blueSky] ([blueSky], emeraldTown, ruby, classic, japanCherry, wine, deepMarine, DEFAULT, plain)
[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.helloworld] [com.mydomain.helloworld]
org.jboss.helloworld
[input] Enter the Java package name for your entity beans [org.jboss.helloworld] [org.jboss.helloworld]
[input] Enter the Java package name for your test cases [org.jboss.helloworld.test] [org.jboss.helloworld.test]
[input] What kind of database are you using? [h2] ([h2], hsql, mysql, oracle, postgres, mssql, db2, sybase, enterprisedb) mysql
[input] Enter the Hibernate dialect for your database [org.hibernate.dialect.MySQLDialect] [org.hibernate.dialect.MySQLDialect]
[input] Enter the filesystem path to the JDBC driver jar [lib/hsqldb.jar] [lib/hsqldb.jar] /Users/pmuir/java/mysql.jar
[input] Enter JDBC driver class for your database [com.mysql.jdbc.Driver] [com.mysql.jdbc.Driver]
[input] Enter the JDBC URL for your database [jdbc:mysql:///test] [jdbc:mysql:///test] jdbc:mysql:///helloworld
[input] Enter database username [sa] [sa] pmuir
[input] Enter database password [] []
[input] skipping input as property hibernate.default_schema.new has already been set.
[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], ) y
[input] Do you want to drop and recreate the database tables and data in import.sql each time you deploy? [n] (y, [n], ) n
[propertyfile] Creating new property file: /Users/pmuir/workspace/jboss-seam/seam-gen/build.properties
[echo] Installing JDBC driver jar to JBoss server
[echo] Type 'seam create-project' to create the new project
BUILD SUCCESSFUL
Total time: 1 minute 32 seconds
~/workspace/jboss-seam $
The tool provides defaults, accept the defaults by pressing enter at the prompt.
Choose the deployment type for your project, EAR deployment or WAR deployment. EAR projects support EJB 3.0 and require Java EE 5. WAR projects do not support EJB 3.0, but can be deployed in a J2EE environment. The packaging of a WAR is simple to understand. If you have installed an EJB3-ready application server like JBoss, choose
EAR. Otherwise, choose WAR. The remaining document assumes an EAR deployment, however, you can follow the same steps for a WAR deployment.
If you are working with an existing data model, inform seam-gen that the tables already exist in the database.
The settings are stored in
seam-gen/build.properties, but you can also modify them by running seam setup a second time.
Create a new project in your Eclipse workspace directory, by typing:
seam new-project
C:\Projects\jboss-seam>seam new-project
Buildfile: build.xml
...
new-project:
[echo] A new Seam project named 'helloworld' was created in the C:\Projects directory
[echo] Type 'seam explode' and go to http://localhost:8080/helloworld
[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: 7 seconds
C:\Projects\jboss-seam>
This copies the Seam jars, dependent jars, and the JDBC driver jar to a new Eclipse project. It also generates the required resources and configuration files; a facelets template file and stylesheet, Eclipse metadata, and an Ant build script. The Eclipse project is automatically deployed to an exploded directory structure in JBoss Enterprise Application Platform when you add the project using
New -> Project... -> General -> Project -> Next, typing the Project name (helloworld in this case), and then clicking Finish. Do not select Java Project from the New Project wizard.
If your default JDK in Eclipse is not a Java SE 6 JDK, select a Java SE 6 compliant JDK using
Project -> Properties -> Java Compiler.
Alternatively, deploy the project from outside Eclipse by typing
seam explode.
Go to
http://localhost:8080/helloworld to see a welcome page. This is a facelets page, view/home.xhtml, using the template view/layout/template.xhtml. You can edit this page, or the template, in Eclipse, and see the results immediately, by clicking refresh in the browser.
The XML configuration documents are mostly standard Java EE and similar between all Seam projects. (They are so easy to write that even seam-gen can do it.)