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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

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? [n] (y, [n])

    [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? [n] (y, [n])

   [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来进行重新部署(增量热部署)。



本文转自 firehare 51CTO博客,原文链接:http://blog.51cto.com/firehare/586520,如需转载请自行联系原作者

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
265
分享
相关文章
NUS CS1101S:SICP JavaScript 描述:二、使用数据构建抽象
NUS CS1101S:SICP JavaScript 描述:二、使用数据构建抽象
93 0
Android开发教程 - 使用Data Binding(七)使用BindingAdapter简化图片加载
本系列目录 使用Data Binding(一)介绍 使用Data Binding(二)集成与配置 使用Data Binding(三)在Activity中的使用 使用Data Binding(四)在Fragment中的使用 ...
1197 0
NUS CS1101S:SICP JavaScript 描述:一、使用函数构建抽象
NUS CS1101S:SICP JavaScript 描述:一、使用函数构建抽象
194 0
IOS开发基础知识:介绍一下 Swift 和 Objective-C,它们之间有什么区别?
IOS开发基础知识:介绍一下 Swift 和 Objective-C,它们之间有什么区别?
492 0
【Pytorch写代码技巧--Einsum】Einsum详解+常用写法
不知大家在看论文代码的时候是否会常常看见 torch.einsum(),这玩意儿看起来是真的抽象,但是深入了解后发现它原来这么好用。
724 0
Swift实用小册11: Subscript下标语法的使用
Swift实用小册11: Subscript下标语法的使用
275 0
Swift实用小册11: Subscript下标语法的使用
Hammer.js分析(一)——基础结构
从github上面将源码下载下来,会发现有个src文件夹。当前版本是2.0.6。
Hammer.js分析(一)——基础结构
iOS开发CoreGraphics核心图形框架之一——CGPath的应用(二)
iOS开发CoreGraphics核心图形框架之一——CGPath的应用
633 0
iOS开发CoreGraphics核心图形框架之一——CGPath的应用(二)
iOS开发CoreGraphics核心图形框架之一——CGPath的应用(一)
iOS开发CoreGraphics核心图形框架之一——CGPath的应用
354 0
iOS开发CoreGraphics核心图形框架之一——CGPath的应用(一)
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等