您的位置:首页 > 编程语言 > Java开发

使用Seam-gen生成基础项目骨架

2010-11-01 00:00 363 查看
Seam-gen 有两种版本:命令行脚本和IDE插件(在开发环境搭建一文中安装的Eclipse插件Jboss Tools套件中就包含着该IDE插件),但由于Seam-gen命令行版本是Ant的一个包装,通过它生成的项目不论是通过命令行还是能过IDE都可以启动,因此确定使用Seam-gen命令行版本来生成基础项目骨架。

进行Seam解压目录,存在两个脚本:seam和seam.bat,它们分别用于Linux/Unix平台和Windows平台。在命令行控制台中,输入seam help可以看seam-gen的简单概要。一般来说使用Seam-gen生成基础项目骨架只需要四步,它们分别是:

seam setup 输入项目原型和数据库信息

seam create-project 创建基础项目结构

seam generate 反向工程数据库,创建管理数据库的CRUD程序

seam explode 将应用程序部署到JBoss应用服务器

一、收集项目信息(输入项目原型和数据库信息)

Seam setup会发出一系列的问题,让seam-gen去收集它需要的信息,才能创建项目。每一个问题都由3部分组成:问题、当前值和一个有效回复列表(如果有的话)。对于每个问题,都需要输入一个回复并按回车键,然后继续下一个问题,为进入下一步收集需要的信息。

$ ./seam setup

SEAM_HOME: /opt/jboss/jboss-seam-2.2.0.GA

Using seam-gen sources from: /opt/jboss/jboss-seam-2.2.0.GA/seam-gen

Buildfile: /opt/jboss/jboss-seam-2.2.0.GA/seam-gen/build.xml

init:

setup:

[echo] Welcome to seam-gen 2.2.0.GA :-)

[echo] Answer each question or hit ENTER to accept the default (in brackets)

[echo]

//输入项目目录

[input] Enter the directory where you want the project to be created (should not contain spaces) [/home/firehare/项目/lpms] [/home/firehare/项目/lpms]

//输入JBOSS应用服务器相关信息

[input] Enter your JBoss AS home directory [/opt/jboss/jboss-5.1.0.GA] [/opt/jboss/jboss-5.1.0.GA]

[input] Enter your JBoss AS domain [default] [default]

//输入GlassFish服务器相关信息(由于我们不使用该服务,所以无需填写)

[input] Enter your GlassFish V2 or V3 home directory (Ignore if you aren't deploying to GlassFish) [/opt/glassfish/glassfish-3.0.1] [/opt/glassfish/glassfish-3.0.1]

[input] Enter your GlassFish domain (Ignore if you aren't deploying to GlassFish) [domain1] [domain1]

//输入项目名单

[input] Enter the project name [lpms] [lpms]

[echo] Accepted project name as: lpms

//采用RichFaces界面(ICEfaces界面性能好一些,但为了能够使用JBossTools插件中的RichFaces,暂用RichFaces界面)

[input] Do you want to use ICEfaces instead of RichFaces?
(y,
)

[input] skipping input as property icefaces.home.new has already been set.

//选择RichFaces界面的皮肤

[input] Select a RichFaces skin [blueSky] ([blueSky], classic, darkX, deepMarine, DEFAULT, emeraldTown, glassX, japanCherry, laguna, ruby, wine)

//确定该项目是做为WAR部署

[input] Is this project deployed as an EAR (with EJB components) or a WAR (with no EJB support)? [war] (ear, [war])

//输入Java类的基包名

[input] Enter the base package name for your Java classes [com.mydomain.lpms] [com.mydomain.lpms]

cn.edu.wzu.cmet.lpms

//输入会话Beans的Java包名

[input] Enter the Java package name for your session beans [cn.edu.wzu.cmet.lpms.action] [cn.edu.wzu.cmet.lpms.action]

//输入实体Beans的Java包名

[input] Enter the Java package name for your entity beans [cn.edu.wzu.cmet.lpms.model] [cn.edu.wzu.cmet.lpms.model]

//输入测试的Java包名

[input] Enter the Java package name for your test cases [cn.edu.wzu.cmet.lpms.test] [cn.edu.wzu.cmet.lpms.test]

//输入数据库类型

[input] What kind of database are you using? [mysql] (hsql, [mysql], derby, oracle, postgres, mssql, db2, sybase, enterprisedb, h2)

//输入JDBC驱动的目录(由于使用的是linux,所以目录同windows下的不一样,Windows下直接输入mysql JDBC驱动所在的目录)

[input] Enter the filesystem path to the JDBC driver jar [/usr/share/java/mysql.jar] [/usr/share/java/mysql.jar]

[input] skipping input as property driver.license.jar.new has already been set.

[input] Enter the Hibernate dialect for your database [org.hibernate.dialect.MySQLDialect] [org.hibernate.dialect.MySQLDialect]

//输入JDBC驱动类名

[input] Enter the JDBC driver class for your database [com.mysql.jdbc.Driver] [com.mysql.jdbc.Driver]

//输入JDBC数据源类

[input] Enter the JDBC DataSource class for your database [com.mysql.jdbc.jdbc2.optional.MysqlDataSource] [com.mysql.jdbc.jdbc2.optional.MysqlDataSource]

//输入数据库JDBC URL

[input] Enter the JDBC URL for your database [jdbc:mysql://localhost:3306/lpms] [jdbc:mysql://localhost:3306/lpms]

jdbc:mysql://localhost:3306/lpms?useUnicode=true&characterEncoding=utf-8

//输入数据库用户名

[input] Enter the database username [lpms] [lpms]

//输入数据库密码

[input] Enter the database password [lpms] [lpms]

[input] skipping input as property hibernate.default_schema.entered has already been set.

[input] Enter the database catalog name (Enter '-' to clear previous value) [] []

//是否使用已有数据库

[input] Are you working with tables that already exist in the database? [y] ([y], n)

[input] Do you want to recreate the database tables and execute import.sql each time you deploy?
(y,
)

[delete] Deleting: /opt/jboss/jboss-seam-2.2.0.GA/seam-gen/build.properties

[propertyfile] Creating new property file: /opt/jboss/jboss-seam-2.2.0.GA/seam-gen/build.properties

[echo] Installing JDBC driver jar to JBoss AS

init:

init-properties:

[echo] /opt/jboss/jboss-5.1.0.GA

validate-workspace:

validate-project:

settings:

[echo] JBoss AS home: /opt/jboss/jboss-5.1.0.GA

[echo] GlassFish home: /opt/glassfish/glassfish-3.0.1

[echo] Project name: lpms

[echo] Project location: /home/firehare/项目/lpms/lpms

[echo] Project type: war

[echo] IceFaces: n

[echo] Action package: cn.edu.wzu.cmet.lpms.action

[echo] Model package: cn.edu.wzu.cmet.lpms.model

[echo] Test package: cn.edu.wzu.cmet.lpms.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://localhost:3306/lpms

[echo] Database username: lpms

[echo] Database password: lpms

[echo]

[echo] Type './seam create-project' to create the new project

BUILD SUCCESSFUL

Total time: 1 minute 16 seconds

这样就完成了项目信息的收集工作

二、创建项目结构(创建基础项目结构)

setup命令只是为seam-gen做好创建项目的准备。真要让seam利用模板生成一个项目,还需要执行sean create-project命令。这样seam将创建一个新的项目,并将配置好该项目的一切,同时还配有一个基于Ant构建的,用于编译、测试、打包和部署的应用程序。

三、创建CRUD程序(项目反向工程数据库,生成管理数据库的CRUD程序)

有了基础的项目骨架之后,就可以进行部署了。但如果是基于已有数据库的话,可以先对数据库进行反向工程,使用seam generate命令可以从一个已有数据库的Schema生成JPA实体类,并生成用来管理这些实体的CRUD用户接口。这些实体在Facelets视图模板中渲染,并且为JavaBean动作类所支持。这样就很方便地构建出了应用程序的原型。

四、项目部署(将应用程序部署到JBoss应用服务器)

应用程序的原型构建好之后,为了让该应用程序启动,需要将其部署到JBoss应用服务器中,在这里为了能够对应用程序进行热部署,使用seam explode命令来进行部署,这样在应用程序更改之后,可以通过重新运行seam explode来进行重新部署(增量热部署)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息