【转】JBoss AS 7 快速上手

谁都会走 提交于 2019-12-04 20:29:11

        JBoss AS7 最近发布了 7.0.0.CR1 版本,CR意即Candidate Release(候选发布版),是JBoss AS在Alpha → Beta之后相对比较完整的一个版本,包含了CDI,JAX-RS等诸多重要特性。这次的7.0.0.CR1版本代号White Rabbit(白兔子)。由于采用了新的MSC内核和JBoss Modules架构,其运行和启动速度真正做到了动若脱兔。让我们一起来体验下吧!

首先是下载JBoss AS 7.0.0.CR1,访问JBoss AS的下载页面:

http://www.jboss.org/jbossas/downloads

将最新版的JBoss AS7下载下来(本文撰写时最新版本为7.0.0.CR1,代号White Rabbit):

除了JBoss AS以外,我们还可以把quickstarts包一起下载下来,这个包里面含有一些样例工程,可以部署进JBoss AS 7,我们稍后讨论。

JBoss AS7的安装包下载完成后,将其解压。解压缩完成后,我们可以看看AS7里面都有什么内容:

/jboss-7.0.0.CR1$ ls
bin               docs              jboss-modules.jar standalone
bundles           domain            modules           welcome-content

可以看到AS7的目录结构和AS6及之前的版本有很大的不同了,这是由于AS7的架构与之前的版本相比,经历了重新架构和代码重写,有了本质上的飞跃。探讨AS7的设计架构不是本文重点,我们继续来看如何运行及启动它:进入bin目录,可以看到有一些命令可供我们使用:

/jboss-7.0.0.CR1/bin$ ls
domain.bat          jboss-admin.bat     standalone.conf     wsconsume.sh
domain.conf         jboss-admin.sh      standalone.conf.bat wsprovide.bat
domain.conf.bat     scripts             standalone.sh       wsprovide.sh
domain.sh           standalone.bat      wsconsume.bat

        AS7提供的命令也和AS6有了很大的不同,熟悉的  run.sh 没有了。取而代之的是 standalone.sh 和  domain.sh 。AS7不再使用统一的  run.sh 加上启动环境参数(default, all)的方式来管理服务,而是将启动方式区分为独立运行(standalone)和域运行(domain)。AS7默认支持多域,在架构上面与原来的组播群集有很大的不同,我会在随后的文章中重点介绍。在这里我们可以首先试玩下以独立模式启动AS7,使用standalone.sh(如果是在Windows下,运行standalone.bat)启动AS7服务器:
 
liweinan@cute:~/projs/jboss-7.0.0.CR1/bin$ ./standalone.sh 
...
20:13:57,559 INFO  [org.jboss.modules] JBoss Modules version 1.0.0.CR4
20:13:58,168 INFO  [org.jboss.msc] JBoss MSC version 1.0.0.CR2
20:13:58,316 INFO  [org.jboss.as] JBoss AS 7.0.0.CR1 "White Rabbit" starting
20:14:00,314 INFO  [org.jboss.as] creating http management service using network interface (management) port (9990) securePort (-1)
...
20:14:00,369 INFO  [org.jboss.as.connector.subsystems.datasources] (Controller Boot Thread) Deploying JDBC-compliant driver class org.h2.Driver (version 1.2)
20:14:00,664 INFO  [org.jboss.as.naming] (Controller Boot Thread) Activating Naming Subsystem
20:14:00,698 INFO  [org.jboss.as.naming] (MSC service thread 1-1) Starting Naming Service 
20:14:00,715 INFO  [org.jboss.as.osgi] (Controller Boot Thread) Activating OSGi Subsystem
20:14:00,767 INFO  [org.jboss.as.security] (Controller Boot Thread) Activating Security Subsystem
20:14:00,784 INFO  [org.jboss.remoting] (MSC service thread 1-2) JBoss Remoting version 3.2.0.Beta2
20:14:00,821 INFO  [org.xnio] (MSC service thread 1-2) XNIO Version 3.0.0.Beta3
20:14:00,856 INFO  [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.0.0.Beta3
20:14:01,193 INFO  [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-4) The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
20:14:01,268 INFO  [org.jboss.as.jmx.JMXConnectorService] (MSC service thread 1-1) Starting remote JMX connector
20:14:01,289 INFO  [org.jboss.as.ee] (Controller Boot Thread) Activating EE subsystem
20:14:01,347 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) Listening on /127.0.0.1:9999
20:14:01,359 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-3) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
20:14:01,395 WARN  [org.jboss.osgi.framework.internal.URLHandlerPlugin] (MSC service thread 1-2) Unable to set the URLStreamHandlerFactory
20:14:01,398 WARN  [org.jboss.osgi.framework.internal.URLHandlerPlugin] (MSC service thread 1-2) Unable to set the ContentHandlerFactory
20:14:01,882 INFO  [org.jboss.as.connector] (MSC service thread 1-1) Starting JCA Subsystem (JBoss IronJacamar 1.0.0.CR2)
20:14:01,987 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) Bound data source [java:jboss/datasources/ExampleDS]
20:14:03,073 INFO  [org.jboss.as.deployment] (MSC service thread 1-2) Started FileSystemDeploymentService for directory /Users/liweinan/projs/jboss-7.0.0.CR1/standalone/deployments
20:14:03,098 INFO  [org.jboss.as] (Controller Boot Thread) JBoss AS 7.0.0.CR1 "White Rabbit" started in 6107ms - Started 91 of 146 services (55 services are passive or on-demand)


 

从启动日志里面可以看出来,AS7使用了新的JBoss Module来加载模块,这是AS7中全新的设计。此外,新的MSC内核的身影也可以在日志中看到。此外,默认启动的模块还包括XNIO高速IO,JCA子系统等。看一下最后一行,AS7的启动时间,在我的Macbook Air 1.4Ghz Core Duo + 2GB内存的低配下达到了惊人的6秒。

        接下来我们试着在AS7上面部署应用玩玩看,刚才一起下载的quickstart包有用了,里面有一些可供部署了例子,我们将压缩包解开,使用里面的numberguess例子,进入到numberguess目录,执行mvn的部署命令:

/jboss-as-quickstarts-7.0.0.CR1/numberguess$ mvn jboss-as:deploy

确保机器里面安装了Maven 3,上面的命令应该可以正确执行,执行完成后,这个例子会被部署到已经运行起来的AS7服务器上,并在AS7的日志输出如下:
22:20:28,184 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) Starting deployment of "jboss-as-numberguess.war"
22:20:28,340 INFO  [org.jboss.weld] (MSC service thread 1-8) Processing CDI deployment: jboss-as-numberguess.war
22:20:28,390 INFO  [org.jboss.weld] (MSC service thread 1-7) Starting Services for CDI deployment: jboss-as-numberguess.war
22:20:28,414 INFO  [org.jboss.weld.Version] (MSC service thread 1-7) WELD-000900 1.1.2 (AS7)
22:20:28,437 INFO  [org.jboss.weld] (MSC service thread 1-3) Starting weld service
22:20:28,777 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-8) Initializing Mojarra 2.0.4 (FCS b09) for context '/jboss-as-numberguess'
22:20:29,514 INFO  [org.jboss.web] (MSC service thread 1-8) registering web context: /jboss-as-numberguess
22:20:29,557 INFO  [org.jboss.as.server.controller] (pool-1-thread-1) Deployed "jboss-as-numberguess.war"


从日志中我们可以看到,AS7检测到待部署的项目需要Weld模块,因此在此时AS7中的Weld模块才被加载,这种加载方式被称为按需加载(on-demand),只有在需要的时候加载相应的模块,从而大大加快了AS7本身的启动速度。

我们来玩玩看这个例子,访问页面:

http://127.0.0.1:8080/jboss-as-numberguess/home.jsf

是一个猜数字的游戏:

         最后提供一些常用的AS7参考资料

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!