Cover | Table of Contents | Colophon
http://www.jboss.org/downloads/index. Once you choose the version of the JBoss application server you want, you'll be taken to the SourceForge.net page to do the actual download. When you get there select one of the prebuilt binary distributions. For JBoss 4.0.2 look for a file named http://www.jboss.org/downloads/index. Once you choose the version of the JBoss application server you want, you'll be taken to the SourceForge.net page to do the actual download. When you get there select one of the prebuilt binary distributions. For JBoss 4.0.2 look for a file named jboss-4.0.2.zip. You'll also see jboss-.4.0.2.tar.gz and jboss-4.0.2.tar.bz2 archives. If either of those formats works better for your platform, feel free to use it instead.-src suffix, as well as RC (release candidate) and DR (developer release) versions of the server. Ignore those for now and stick to the production binaries. In this book we will work from the jboss-4.0.2.tar.gz release.
[bin]$ ./run.sh
=========================================================
JBoss Bootstrap Environment
JBOSS_HOME: /Users/samjr/jboss-4.0.2RC1
JAVA: java
JAVA_OPTS: -server -Xms128m -Xmx128m -Dprogram.name=run.sh
CLASSPATH: /Users/samjr/jboss-4.0.2RC1/bin/run.jar:/lib/tools.jar
=========================================================
05:02:58,197 INFO [Server] Starting JBoss (MX MicroKernel)...
05:02:58,230 INFO [Server] Release ID: JBoss [Zion] 4.0.2RC1 (build:
CVSTag=JBoss_4_0_2_RC1 date=200503140913)
05:02:58,232 INFO [Server] Home Dir: /Users/samjr/jboss-4.0.2RC1
05:02:58,233 INFO [Server] Home URL: file:/Users/samjr/jboss-4.0.2RC1/
05:02:58,235 INFO [Server] Library URL: file:/Users/samjr/jboss-4.0.2RC1/lib/
05:02:58,238 INFO [Server] Patch URL: null
05:02:58,256 INFO [Server] Server Name: default
05:02:58,258 INFO [Server] Server Home Dir: /Users/samjr/jboss-4.0.2RC1/
server/default
05:02:58,259 INFO [Server] Server Home URL: file:/Users/samjr/jboss-4.0.
2RC1/server/default/
05:02:58,261 INFO [Server] Server Data Dir: /Users/samjr/jboss-4.0.2RC1/
server/default/data
05:02:58,262 INFO [Server] Server Temp Dir: /Users/samjr/jboss-4.0.2RC1/
server/default/tmp
05:02:58,264 INFO [Server] Server Config URL: file:/Users/samjr/jboss-4.0.
2RC1/server/default/conf/
05:02:58,265 INFO [Server] Server Library URL: file:/Users/samjr/jboss-4.0.
2RC1/server/default/lib/
05:02:58,267 INFO [Server] Root Deployment Filename: jboss-service.xml
05:02:58,324 INFO [Server] Starting General Purpose Architecture (GPA)...
[Lots of startup output removed for brevity]
05:04:05,834 INFO [TomcatDeployer] deploy, ctxPath=/quote, warUrl=file:/
Users/samjr/jboss-4.0.2RC1/server/default/tmp/deploy/tmp14739quote.war/
05:04:06,348 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
05:04:06,868 INFO [ChannelSocket] JK2: ajp13 listening on /0.0.0.0:8009
05:04:06,956 INFO [JkMain] Jk running ID=0 time=0/199 config=null
05:04:07,092 INFO [Server] JBoss (MX MicroKernel) [4.0.2RC1 (build:
CVSTag=JBoss_4_0_2_RC1 date=200503140913)] Started in 1m:7s:977ms
http://localhost:8080) and choosing the JMX Console link. This will take you to the jmx-console web application at http://localhost:8080/jmx-console. When you're there, you'll see something like Figure 1-2.
jboss.system domain and choose the type=Server MBean link. On the MBean page, scroll down to the operations section and click the "Invoke" button for the shutdown() operation.
03:50:02,412 INFO [Server] Shutdown complete
minimal that you can add other services to later. You can copy the minimal server configuration folder to a new folder in the server folder and call it my_server_config. On Unix this would be cp -R minimal my_server_config.
[bin]$ ./run.sh -c my_server_config
=========================================================
JBoss Bootstrap Environment
JBOSS_HOME: /Users/samjr/jboss-4.0.2RC1
JAVA: java
JAVA_OPTS: -server -Xms128m -Xmx128m -Dprogram.name=run.sh
CLASSPATH: /Users/samjr/jboss-4.0.2RC1/bin/run.jar:/lib/tools.jar
=========================================================
05:49:22,213 INFO [Server] Starting JBoss (MX MicroKernel)...
05:49:22,217 INFO [Server] Release ID: JBoss [Zion] 4.0.2RC1 (build:
CVSTag=JBoss_4_0_2_RC1 date=200503140913)
05:49:22,220 INFO [Server] Home Dir: /Users/samjr/jboss-4.0.2RC1
05:49:22,221 INFO [Server] Home URL: file:/Users/samjr/jboss-4.0.2RC1/
05:49:22,223 INFO [Server] Library URL: file:/Users/samjr/jboss-4.0.2RC1/lib/
05:49:22,226 INFO [Server] Patch URL: null
05:49:22,244 INFO [Server] Server Name: my_server_config
05:49:22,246 INFO [Server] Server Home Dir: /Users/samjr/jboss-4.0.
2RC1/server/my_server_config
05:49:22,247 INFO [Server] Server Home URL: file:/Users/samjr/jboss-4.0.
2RC1/server/my_server_config/
05:49:22,249 INFO [Server] Server Data Dir: /Users/samjr/jboss-4.0.2RC1/server/my_
server_config/data
05:49:22,250 INFO [Server] Server Temp Dir: /Users/samjr/jboss-4.0.2RC1/
server/my_server_config/tmp
05:49:22,251 INFO [Server] Server Config URL: file:/Users/samjr/jboss-4.0.
2RC1/server/my_server_config/conf/
05:49:22,285 INFO [Server] Server Library URL: file:/Users/samjr/jboss-4.0.
2RC1/server/my_server_config/lib/
05:49:22,287 INFO [Server] Root Deployment Filename: jboss-service.xml
05:49:22,294 INFO [Server] Starting General Purpose Architecture (GPA)...
[More startup information]
05:50:44,641 INFO [Server] JBoss (MX MicroKernel) [4.0.2RC1 (build:
CVSTag=JBoss_4_0_2_RC1 date=200503140913)] Started in 1m:21s:849ms
http://ant.apache.org/bindownload.cgi and download a binary distribution. Choose a binary format that is appropriate for your system.ANT_HOME environment variable to point at the directory in which you unpacked Ant, which is /Users/samjr/apache-ant-1.6.2 in this example. You also need to add Ant's bin directory to your command path. In this example it is /Users/samjr/apache-ant-1.6.2/bin. You can find more information about configuring and installing Ant in the Ant manual, available online at http://ant.apache.org/manual/http://www.oreilly.com. You'll be able to find it on the same page as this book's listing.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Random" %>
<%
//List of sayings
String[ ] quotes = {
"Before God we are all equally wise - and equally foolish",
"I never think of the future - it comes soon enough",
"Imagination is more important than knowledge...",
"Reality is merely an illusion, albeit a very persistent one",
"The important thing is not to stop questioning",
"The secret to creativity is knowing how to hide your sources",
"Science without religion is lame, religion without science is blind",
"Everything that is really great and inspiring is created by" +
"the individual who can labor in freedom"
};
ArrayList list = new ArrayList(Arrays.asList(quotes));
Random r = new Random();
int x = r.nextInt(list.size());
String saying = (String)list.get(x);
saying = saying + " -- Albert Einstein";
pageContext.setAttribute("saying", saying);
%>
<html>
<head>
<title>JBoss Notebook Chapter 2 Demo 1</title>
</head>
<body>
<br>
<c:set var="sessionCount" scope="session"
value="${sessionCount + 1}" />
<c:set var="applicationCount" scope="application"
value="${applicationCount + 1}" />
<h1>
<font color="#1230cb">The Great Albert Einstein Quote Machine</font>
</h1>
<h3>
<spacer size="32" type="horizontal">
<font color="#a6a6a6">
${saying}
</font>
</h3>
<br><br>
You've visited this application ${sessionCount}
times in this session
<br>
and the application has been visited ${applicationCount}
times by you and others.
</body>
</html>
url-pattern from the servlet-mapping section in the web.xmlfile. In our case the WAR file is named quote.war and the servlet mapping is quote. This gives us the path /quote/quote, which we put together with the host and port portion of a URL.http://localhost:8080/quote/quote. You should see something like Figure 2-3.
jar command:
[deploy]$ mkdir quote2.war
[deploy]$ cd quote2.war/
[quote2.war]$ jar xvf ../quote.war
created: META-INF/
extracted: META-INF/MANIFEST.MF
extracted: quote.jsp
created: WEB-INF/
created: WEB-INF/lib/
extracted: WEB-INF/lib/jstl.jar
extracted: WEB-INF/lib/standard.jar
extracted: WEB-INF/web.xml
[quote2.war]$ ls
META-INF WEB-INF quote.jsp
http://localhost:8080/quote2/quote.http://localhost:8080/web-console/. You'll see a screen like Figure 2-5.
QuoteServlet in it, which is what we told it to create from the quote.jsp file in web.xml. If you choose QuoteServlet, you will see servlet statistics about it, including the number of times it has been invoked (see Figure 2-6).
http://localhost:8080/quote/quote and then click QuoteServlet again to cause the web console application to refresh, at which point you should see the "# Invocations" count go up (see Figure 2-7).
08:56:13,629 INFO [TomcatDeployer] undeploy, ctxPath=/quote, warUrl=file:/
Users/samjr/jboss-4.0.2/server/default/tmp/deploy/tmp12813quote.war/
undeploy target that accomplishes this. As you can see, the build file is just deleting the file from the deploy directory:
[quote]$ ant undeploy
Buildfile: build.xml
undeploy:
[echo] In undeploy
[delete] Deleting 1 files from /users/samjr/jboss-4.0.2/server/default/deploy
BUILD SUCCESSFUL
TaskBean
and CommentBean
, and one local session bean, TaskMasterBean. You can find the source code for all the beans in the
src/com/oreilly/jbossnotebook/todo/ejb directory.ejbdoclet target, which is responsible for invoking the XDoclet-provided ejbdoclet task. This code-generation step needs to take place right before the compile step.
<target name="ejbdoclet" depends="init">
<mkdir dir="dd/ejb" />
<ejbdoclet destdir="${gen.src.dir}" ejbSpec="2.1">
<fileset dir="${src.dir}">
<include name="**/*Bean.java"/>
</fileset>
<deploymentdescriptor destdir="dd/ejb"/>
<homeinterface/>
<remoteinterface/>
<localinterface/>
<localhomeinterface/>
<utilobject includeGUID="true" cacheHomes="true" />
<valueobject pattern="{0}"/>
<entitycmp/>
<session/>
</ejbdoclet>
</target>
webdoclet task invokes XDoclet for us:
<target name="webdoclet" depends="init">
<mkdir dir="dd/web" />
<webdoclet destdir="${gen.src.dir}" mergedir="${merge.dir}">
<fileset dir="${src.dir}">
<include name="**/*Servlet.java"/>
<include name="**/*Filter.java"/>
</fileset>
<deploymentdescriptor servletspec="2.4"
destdir="dd/web"
distributable="false"/>
</webdoclet>
</target>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
pinky=duh
brain=conquest
User role in the web-security.xml merge file. We need to make sure that the application users have that role:
pinky=User
brain=User
brain=User,Admin
[todo]$ jar tf build/jars/todo.ear
META-INF/
META-INF/application.xml
todo.jar
todo.war
<application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>JBoss Notebook ToDo Application</display-name>
<description>JBoss Notebook ToDo Application</description>
<module>
<ejb>todo.jar</ejb>
</module>
<module>
<web>
<web-uri>todo.war</web-uri>
<context-root>todo</context-root>
</web>
</module>
</application>
todo, which is what JBoss would have used had we deployed the todo.war file separately.http://localhost:8080/jmx-console, if you forgot.
database=localDB,service=Hypersonic MBean in the jboss domain.startDatabaseManager operation. Invoking this operation launches the HSQL Database Manager, shown in Figure 3-2.
http://dev.mysql.com for every major computing platform. You'll want to download and install the most current MySQL distribution available for your platform. We'll be working from the MySQL Standard 4.1.8 GA version.http://dev.mysql.com for every major computing platform. You'll want to download and install the most current MySQL distribution available for your platform. We'll be working from the MySQL Standard 4.1.8 GA version.