此内容没有您所选择的语言版本。

3.2. Setting up a new project


Task

Create a Seam project using the seam-gen command line tool.

Prerequisites:

  • JBoss Enterprise Application Platform 5
  • Ant 1.7.0
  • A recent version of Eclipse.
  • A recent version of the JBoss IDE plug-in for Eclipse.
  • Add your EAP instance to the JBoss Server View in Eclipse.
  • The TestNG plug-in for Eclipse.
  • An EAP server running in debug mode.
  • A command prompt in the directory where you unzipped the Seam distribution.

Procedure 3.1. Create a Seam project with seam-gen

  1. Configure seam-gen for your environment by typing the following in your command line interface:
    cd seam_distribution_dir; ./seam setupcd seam_distribution_dir; ./seam setupcd seam_distribution_dir; ./seam setup
    Copy to Clipboard Toggle word wrap
    The following output will be displayed:
    Buildfile: build.xml
    
    init:
    
    setup:
    
        [echo] Welcome to seam-gen 2.2.2.EAP5 :-)
    
        [echo] Answer each question or hit ENTER to accept the default (in brackets)
    
        [echo]
    Copy to Clipboard Toggle word wrap
    You will then receive the following prompts for required information:
    1. [input] Enter the directory where you want the project to be created (should not contain spaces) [/home/<username>/projects] [/home/<username>/projects]
      Copy to Clipboard Toggle word wrap
      Pressing Enter will accept the shown default (/home/<username>/projects).
      Alternatively you can enter a different value.
    2. [input] Enter your JBoss AS home directory [/var/lib/jbossas] [/var/lib/jbossas]
      Copy to Clipboard Toggle word wrap
      Again, press Enter to accept the default or enter a new value:
      /home/<username>/path/to/jboss-as
      Copy to Clipboard Toggle word wrap
    3. [input] Enter your JBoss AS domain [default] [default]
      Copy to Clipboard Toggle word wrap
      If you use a custom domain, enter it here.
    4. [input] Enter the project name [myproject] [myproject]
      Copy to Clipboard Toggle word wrap
      Enter the name of your project. Not entering a name will default to naming your project myproject.
      For this example, the project will be called helloworld.
      [echo] Accepted project name as: helloworld
      Copy to Clipboard Toggle word wrap
    5. [input] Select a RichFaces skin [glassX] (blueSky, classic, darkX, deepMarine, DEFAULT, emeraldTown, [glassX], japanCherry, laguna, ruby, wine)
      Copy to Clipboard Toggle word wrap
      You can choose a skin for your project from the list presented. You can see that glassX is the default.
    6. [input] Is this project deployed as an EAR (with EJB components) or a WAR (with no EJB support)? [war] (ear, [war])
      Copy to Clipboard Toggle word wrap
      Enter the appropriate archive format.
      EAR projects support Enterprise JavaBeans 3.0 (EJB3) and require Java EE 5. WAR projects do not support EJB3, but can be deployed to a J2EE environment, and their packaging is simpler.
      If you have an EJB3-ready application server like JBoss installed, choose ear. Otherwise, choose war. This tutorial assumes you are using an EAR deployment, but you can follow these steps even if your project is WAR-deployed.
    7. [input] Enter the base package name for your Java classes [com.mydomain.helloworld] [com.mydomain.helloworld]
      
      [input] Enter the Java package name for your session beans [com.mydomain.helloworld.action] [com.mydomain.helloworld.action]
      
      [input] Enter the Java package name for your entity beans [com.mydomain.helloworld.model] [com.mydomain.helloworld.model]
      
      [input] Enter the Java package name for your test cases [com.mydomain.helloworld.test] [com.mydomain.helloworld.test]
      
      Copy to Clipboard Toggle word wrap
      You will be prompted to nominate the package names for your Java classes, session beans, entity beans and test cases.
    8. [input] What kind of database are you using? [hsql] ([hsql], mysql, derby, oracle, postgres, mssql, db2, sybase, enterprisedb, h2)
      Copy to Clipboard Toggle word wrap
      Nominate your database, mysql, for example. The default is hsql.
    9. [input] Enter the filesystem path to the JDBC driver jar [] []
      Copy to Clipboard Toggle word wrap
      Enter the path to your system's JDBC driver; /usr/share/java/mysql.jar for example.
      You may see the following output:
      [input] skipping input as property driver.license.jar.new has already been set.
      Copy to Clipboard Toggle word wrap
    10. [input] Enter the Hibernate dialect for your database [org.hibernate.dialect.MySQLDialect] [org.hibernate.dialect.MySQLDialect]
      Copy to Clipboard Toggle word wrap
      Nominate the appropriate Hibernate dialect.
    11. [input] Enter the JDBC DataSource class for your database [com.mysql.jdbc.jdbc2.optional.MysqlDataSource] [com.mysql.jdbc.jdbc2.optional.MysqlDataSource]
      
      [input] Enter the JDBC driver class for your database [com.mysql.jdbc.Driver] [com.mysql.jdbc.Driver]
      
      Copy to Clipboard Toggle word wrap
      You will be prompted to nominate the JDBC classes for your instance.
    12. [input] Enter the JDBC URL for your database [jdbc:mysql:///test] [jdbc:mysql:///test]
      Copy to Clipboard Toggle word wrap
      The default URL will differ based on your response to the earlier database question.
    13. [input] Enter the database username [sa] [sa]
      Copy to Clipboard Toggle word wrap
      Nominate the username for access to the database, for example root.
    14. [input] Enter the database password [] []
      Copy to Clipboard Toggle word wrap
      Set the password for the above username.
      You may see the following message:
      [input] skipping input as property hibernate.default_schema.entered has already been set.
      Copy to Clipboard Toggle word wrap
    15. [input] Enter the database schema name (Enter '-' to clear previous value) [] []
      
      [input] Enter the database catalog name (Enter '-' to clear previous value) [] []
      Copy to Clipboard Toggle word wrap
      Name the database schema and catalogue as prompted.
    16. [input] Are you working with tables that already exist in the database? [n] (y, [n])
      Copy to Clipboard Toggle word wrap
      If you are working with an existing data model, make sure to tell seam-gen that tables already exist in the database.
    17. [input] Do you want to recreate the database tables and execute import.sql each time you deploy? [n] (y, [n])
      Copy to Clipboard Toggle word wrap
      Again, answer as appropriate.
    18. You will see the following output. Some details will differ in your instance, based on answers you provided to the above questions:
      [propertyfile] Creating new property file: /home/path/to/jboss-as/seam/seam-gen/build.properties
      
          [echo] Installing JDBC driver jar to JBoss AS
      
          [copy] Copying 1 file to /home/path/to/jboss-as/server/default/lib
      
      init:
      
      init-properties:
      
          [echo] /home/path/to/jboss-as/
      
      validate-workspace:
      
      validate-project:
      
      settings:
      
          [echo] JBoss AS home: /home/path/to/jboss-as/
      
          [echo] Project name: helloworld
      
          [echo] Project location: /home/path/to/projects/helloworld
      
          [echo] Project type: ear
      
          [echo] Action package: com.mydomain.helloworld.action
      
          [echo] Model package: com.mydomain.helloworld.model
      
          [echo] Test package: com.mydomain.helloworld.test
      
          [echo] JDBC driver class: com.mysql.jdbc.Driver
      
          [echo] JDBC DataSource class: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
      
          [echo] Hibernate dialect: org.hibernate.dialect.MySQLDialect
      
          [echo] JDBC URL: jdbc:mysql:///test
      
          [echo] Database username: root
      
          [echo] Database password:
      
          [echo]
      
          [echo] Type './seam create-project' to create the new project
          
      BUILD SUCCESSFUL
      Total time: 2 minutes 14 seconds
      
      Copy to Clipboard Toggle word wrap
      The time shown in this example is non-indicative of the actual time it will take to complete this task.
  2. Create a new project in our Eclipse workspace directory by entering one of the following commands:
    ./seam create-project
    Copy to Clipboard Toggle word wrap
    Or
    ./seam new-project
    Copy to Clipboard Toggle word wrap
    You will see the following output:
    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>
    
    Copy to Clipboard Toggle word wrap
    This copies the Seam JARs, dependent JARs and the JDBC driver JAR to a new Eclipse project. It generates all required resources and configuration files, a Facelets template file and stylesheet, along with Eclipse metadata and an Ant build script. The Eclipse project will be automatically deployed to an exploded directory structure in JBoss as soon as you add the project. To add the project, go to New Project... General Project Next, type the Project name (in this case, helloworld), and then click Finish. Do not select Java Project from the New Project wizard.
If your default JDK in Eclipse is not Java SE 6 JDK, you will need to select a compliant JDK. Go to Project Properties Java Compiler.
Alternatively, you can deploy the project from outside Eclipse by typing seam explode.
The welcome page can be found at http://localhost:8080/helloworld. This is a Facelets page (view/home.xhtml) created using the template found at view/layout/template.xhtml. You can edit the welcome page or the template in Eclipse, and see the results immediately by refreshing your browser.
XML configuration documents will be generated in the project directory. These may appear complicated, but they are comprised primarily of standard Java EE, and require little alteration, even between Seam projects.
There are three database and persistence configurations in the generated project. persistence-test.xml and import-test.sql are used while running TestNG unit tests against HSQLDB. The database schema and test data in import-test.sql is always exported to the database before tests are run. myproject-dev-ds.xml, persistence-dev.xml and import-dev.sql are used during application deployment to your development database. If you told seam-gen that you were working with an existing database, the schema may be exported automatically upon deployment. myproject-prod-ds.xml, persistence-prod.xml and import-prod.sql are used during application deployment to your production database. The schema will not be exported automatically upon deployment.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat