27
Professional Open Source™ © JBoss, Inc. 2003-2005. 1 February 7, 2022 Deploying Applications ”Make EAR, not WAR.”

Deploying Applications

Embed Size (px)

DESCRIPTION

Deploying Application in JBoss

Citation preview

Page 1: Deploying Applications

Professional Open Source™

© JBoss, Inc. 2003-2005. 1April 11, 2023

Deploying Applications

”Make EAR, not WAR.”

Page 2: Deploying Applications

© JBoss, Inc. 2003-2005 2

Professional Open Source™

Topics and Objectives

In this section we will cover:– Different application packages that exist in J2EE and JBoss

– Hot- and redeploy of applications and services

– Expanded deployments (no archive packages)

– In the end, hands-on exercise on deploying applications on JBoss

Page 3: Deploying Applications

© JBoss, Inc. 2003-2005 3

Professional Open Source™

J2EE Application Packaging

J2EE defines packaging structure for middleware applications– Essentially these are all ZIP archives

– Use your favorite tools to manipulate them:

• jar, zip, etc. from command line

• WinZip, Windows Explorer, etc. from a GUI

– Packages usually contain

• Java class files developers produce

• Package configuration file – deployment descriptor

• Resource files for the application– Configuration files, image files, HTML files, XML files, etc.

Page 4: Deploying Applications

© JBoss, Inc. 2003-2005 4

Professional Open Source™

J2EE Application Packaging

In JBoss you will find these basic package types:– Web Archive (*.war)

• For web applications (Servlets and Java Server Pages on Tomcat)

– EJB Archive (*.jar)

• Enterprise JavaBean components

– Enterprise Application Archive (*.ear)

• Collects Web Archives and EJB Archives into a single deployable unit

– Resource Adapter Archives (*.rar)

• Connectors from application server to enterprise information systems (EIS): RDBMS, SAP/R3, CICS, etc.

– Web Service Archives (*.wsr)

• Components accessible via SOAP and other web service protocols

– JBoss Service Archive (*.sar)

• Service implementations deployed on JBoss microkernel

Page 5: Deploying Applications

© JBoss, Inc. 2003-2005 5

Professional Open Source™

J2EE Application Packaging

Example: Web Archive (*.war)– Contains web tier applications

• Servlet/JSP implementations• Related resource files for HTTP output• Deployment descriptors: web.xml and

jboss-web.xml

Page 6: Deploying Applications

© JBoss, Inc. 2003-2005 6

Professional Open Source™

JBoss Deployment

How to deploy HelloAdmin.war ?– Locate ”deploy” directory in your server

configuration

HelloAdmin.war

– Choose the ”deploy” directory of your server configuration

run –c MyConfig

vs.

run –c default

– Use GUI tools (e.g. Explorer) to drag and drop the application package to your ”deploy” directory

– Or use command line tools

> mv HelloAdmin.war server/MyConfig/deploy

You can deploy packages on a live server. This is what we call hot-deployment.

You can deploy packages on a live server. This is what we call hot-deployment.

Page 7: Deploying Applications

© JBoss, Inc. 2003-2005 7

Professional Open Source™

When you drop the HelloAdmin.war file to deploy directory– It is picked up by a DeploymentScanner service

• Configured in conf/jboss-service.xml

• You can change:– Scanning interval– Directories that are scanned (URLs)

– You’ll notice in the server console that the deployment is picked up

• Or in the log/server.log with much more detail

JBoss Deployment

21:51:08,477 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080

21:51:08,707 INFO [ChannelSocket] JK2: ajp13 listening on /0.0.0.0:8009

21:51:08,717 INFO [JkMain] Jk running ID=0 time=0/110 config=null

21:51:08,727 INFO [Server] JBoss (MX MicroKernel) [4.0.1sp1 (build: CVSTag=JBoss_4_0_1_SP1 date=200502160314)] Started in 47s:358ms

21:53:34,397 INFO [TomcatDeployer] deploy, ctxPath=/HelloAdmin, warUrl=file:/C:/Programs/JBoss/server/MyConfig/deploy/HelloAdmin.war/

Page 8: Deploying Applications

© JBoss, Inc. 2003-2005 8

Professional Open Source™

JBoss Deployment

What you can read from this line:

21:53:34,397 INFO [TomcatDeployer] deploy, ctxPath=/HelloAdmin, warUrl=file:/C:/Programs/JBoss/server/MyConfig/deploy/HelloAdmin.war/

– A web application archive (WAR) was succesfully installed.

– Context path of the web application is /HelloAdmin

• You can verify it by using your browser to connect to http://localhost:8080/HelloAdmin

– Defaults to package name: HelloAdmin.war /HelloAdmin– HTTP connector runs at port 8080 by default

– The location of the file that was deployed

You can find a lot more detail (DEBUG level) about this deployment in server/<configuration>/log/server.log. This is especially useful in case of failed deployments.

Page 9: Deploying Applications

© JBoss, Inc. 2003-2005 9

Professional Open Source™

JBoss Deployment

You can also try and locate your deployed package from the web-console:

– http://localhost:8080/web-console

Page 10: Deploying Applications

© JBoss, Inc. 2003-2005 10

Professional Open Source™

JBoss Undeployment And Redeployment

How to undeploy a service or application:– Delete package from deploy directory

00:44:38,135 INFO [TomcatDeployer] undeploy, ctxPath=/HelloAdmin, warUrl=file:/C:/Programs/JBoss/server/MyConfig/deploy/HelloAdmin.war

How to redeploy a service or application:– Change the timestamp of the deploy package (e.g. touch)– Causes an undeploy – deploy sequence

00:52:23,605 INFO [TomcatDeployer] undeploy, ctxPath=/HelloAdmin, warUrl=file:/C:/Programs/JBoss/server/MyConfig/deploy/HelloAdmin.war

00:52:23,695 INFO [TomcatDeployer] deploy, ctxPath=/HelloAdmin, warUrl=file:/C:/Programs/JBoss/server/MyConfig/deploy/HelloAdmin.war

Page 11: Deploying Applications

Professional Open Source™

© JBoss, Inc. 2003-2005. 11April 11, 2023

Other Deployment Options”On the road to Timbuktu.”

Page 12: Deploying Applications

© JBoss, Inc. 2003-2005 12

Professional Open Source™

Expanded Deployments

Services and applications can be deployed as directories – Previous examples used ZIP archives (*.war, *.jar, *.ear, *.sar, etc.)

– Zip archives are easy to distribute but sometimes unpleasant to manage

• When making configuration changes you must:1. Undeploy

2. Extract

3. Modify

4. Re-zip

5. Deploy

All packages can be deployed as expanded directories instead– Allows for direct file modification on a deployed package

Page 13: Deploying Applications

© JBoss, Inc. 2003-2005 13

Professional Open Source™

Expanded Deployments

How to deploy a directory package– Simply create a directory with a proper

extension and follow the zip archive structure inside the directory

Instead of deploying this... Deploy this.

HelloAdmin.war

Page 14: Deploying Applications

© JBoss, Inc. 2003-2005 14

Professional Open Source™

Expanded Deployments

How to undeploy directory package– Same as zip package Delete the directory

How to redeploy directory package– Change the timestamp on the deployment descriptor

Note – changing the timestamp on the directory itself will not work.

Deployment descriptors for different package types:

EJB JAR: META-INF/ejb-jar.xml WAR: WEB-INF/web.xml

EAR: META-INF/application.xml SAR: META-INF/jboss-service.xml

Note – the descriptor paths are case sensitive.

Page 15: Deploying Applications

© JBoss, Inc. 2003-2005 15

Professional Open Source™

Expanded Deployments

Example:– Changing the context root of a deployed servlet

– Locate the WEB-INF/jboss-web.xml deployment descriptor:

<jboss-web>

<context-root>/AdminApplication</contextroot>

</jboss-web>

<jboss-web>

<context-root>/AdminApplication</contextroot>

</jboss-web>

– Touch the web.xml file (timestamp changes)

• existing web application at http://localhost:8080/HelloAdmin will undeploy and redeploy at http://localhost:8080/AdminApplication.

Page 16: Deploying Applications

© JBoss, Inc. 2003-2005 16

Professional Open Source™

Nested Deployment

You can nest service and application packages– When packages are deployed they are searched recursively for

sub-packages

– Nested expanded deployments are also supported

– Redeployment and undeployment only work on the top level package

• You must manage the entire tree as one deployment

• You can’t redeploy or undeploy individual sub-packages

Page 17: Deploying Applications

© JBoss, Inc. 2003-2005 17

Professional Open Source™

Default JBoss Web Application

How to change the default JBoss page?– Tomcat servlet container is embedded

inside JBoss server

– It is located under deploy/jbossweb-tomcat50.sar

– Under that directory there’s a special web archive, ROOT.war

– Simply modify this archive to become your default web application

• Or remove completely

• Or use root (’/’) as the context root of an existing application

Page 18: Deploying Applications

© JBoss, Inc. 2003-2005 18

Professional Open Source™

Configuration File Deployment

What are the service.xml files in the deploy directory?– You notice in ”deploy” directory there are several XML files that follow the

naming convention <name>-service.xml

– These are deployment descriptors deployed without associated Java class libraries

– Sometimes it makes sense to deploy just a new instance of an existing service

• No need to package classes

• Easy modification

• Deployment/undeployment works the same as with full service packages

• <name>-service.xml is the equivalent of jboss-service.xml in a SAR package

Page 19: Deploying Applications

© JBoss, Inc. 2003-2005 19

Professional Open Source™

Conclusion

– JBoss has dynamic deployment for ease-of-use

• Simple add/remove of files

• Can be done on a live server instance

– Service and application packages are ZIP files

• Contain deployment descriptors specific to each package type

• SAR, EAR, WAR, RAR, WSR, JAR

– Deployment is possible with expanded directories

– Redeployment is triggered by touching the deployment descriptor

Page 20: Deploying Applications

© JBoss, Inc. 2003-2005 20

Professional Open Source™

Test

– Touching jboss-service.xml redeploys a service implementation (T/F) ?

– Touching jboss-web.xml redeploys web application (T/F) ?

– Changing a web application’s URL path requires a restart (T/F) ?

– Tomcat deploys *.tar archives from ROOT.war directory (T/F) ?

– Deleting a package from deploy directory uninstalls it (T/F) ?

– JBoss supports hot-deployment of all package types (T/F) ?

– J2EE packages require a proprietary deployment tool to modify (T/F) ?

Page 21: Deploying Applications

© JBoss, Inc. 2003-2005 21

Professional Open Source™

Lab Deployment

LAB-DEPLOYMENT

Page 22: Deploying Applications

© JBoss, Inc. 2003-2005 22

Professional Open Source™

Lab Deployment

An Hello World ServiceThis is a simple example of a JBoss Service. It lets youConfigure a message, which it prints out at start/stop. There is also a printMessage() operation and the message is configurable as an attribute.

The Management InterfaceThe key things are to extend ServiceMBean and define our management interface. package com.acme; import org.jboss.system.ServiceMBean; public interface HelloWorldServiceMBean extends ServiceMBean{ // Configure getters and setters for the message attribute String getMessage(); void setMessage(String message); // The print message operation void printMessage();}

Page 23: Deploying Applications

© JBoss, Inc. 2003-2005 23

Professional Open Source™

Lab Deployment

The Service ImplementationNow we have to implement our management interface and the start/stop example lifecyle. We must implement our management according to the jmx spec

and we extend ServiceMBeanSupport to do the heavy lifting.

package com.acme; import org.jboss.system.ServiceMBeanSupport; public class HelloWorldService extends ServiceMBeanSupport implements HelloWorldServiceMBean{ // Our message attribute private String message = "Sorry no message today"; 

Page 24: Deploying Applications

© JBoss, Inc. 2003-2005 24

Professional Open Source™

Lab Deployment

// The lifecycle

protected void startService() throws Exception

{

log.info("Starting with message=" + message);

}

protected void stopService() throws Exception

{

log.info("Stopping with message=" + message);

}

}

Page 25: Deploying Applications

© JBoss, Inc. 2003-2005 25

Professional Open Source™

Lab Deployment

The deployment descriptor (jboss-service.xml)

<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="com.acme.HelloWorldService" name="acme.com:service=HelloWorld"> <attribute name="Message">Hello World</attribute> </mbean></server>

Page 26: Deploying Applications

© JBoss, Inc. 2003-2005 26

Professional Open Source™

Lab Deployment

Now create a SAR for your service

This is a jar file or directory (called hello-world.sar in this example) with the following structure:

hello-world.sarhello-world.sar/META-INF/jboss-service.xmlhello-world.sar/com/acme/HelloWorldService.classhello-world.sar/com/acme/HelloWorldServiceMBean.class

Page 27: Deploying Applications

© JBoss, Inc. 2003-2005 27

Professional Open Source™

Lab Deployment

// Getters and Setters public String getMessage() { return message; } public void setMessage(String message) { this.message = message; }

// The print message operation void printMessage();}

// The printMessage operation

public void printMessage()

{

log.info(message);

}