Tag Archives: JBoss AS

How to Enable an Application with the JBoss AS CLI

Domain Mode

deploy --name=<Deployment Name> <--all-server-groups | --server-groups=<Server Group Name>>

Stand-Alone Mode

deploy --name=<Deployment Name>
Advertisements

How to Prevent the “JAR Plague” in JBoss AS 5

1) Set jboss.vfs.forceCopy to false, or

2) Set jboss.vfs.forceCanonical to false, or

3) Add the farm directory to the map of permanent roots in the <JBoss AS Install Dir>/server/<Profile>/conf/bootstrap/vfs.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="urn:jboss:bean-deployer:2.0">
  ...
  <bean name="VFSCache">
    ...
    <property name="permanentRoots">
      <map keyClass="java.net.URL" valueClass="org.jboss.virtual.spi.ExceptionHandler">
        ...
        <entry>
          <key>${jboss.common.lib.url}farm</key>
          <value><inject bean="VfsNamesExceptionHandler"/></value>
        </entry>
      </map>
    </property>
    ...
  </bean>
  ...
</deployment>

How to Declare a Dependency on a Module in JBoss EAP

EJB JAR/WAR w/ jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
  <dependencies>
    <module name="br.eti.fernandoribeiro.sample" slot="1.0" />
    ...
  </dependencies>
</jboss-deployment-structure>

EJB JAR/WAR w/ MANIFEST.MF

Dependencies: br.eti.fernandoribeiro.sample:1.0 ...

EAR w/ jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
  <sub-deployment name="sample.jar">
    <dependencies>
      <module name="br.eti.fernandoribeiro.sample" slot="1.0" />
      ...
    </dependencies>
  </sub-deployment>
  <sub-deployment name="sample.war">
    <dependencies>
      <module name="br.eti.fernandoribeiro.sample" slot="1.0" />
      ...
    </dependencies>
  </sub-deployment>
  ...
</jboss-deployment-structure>

You can find more details in chapter 3 of the Development Guide.

How to Create a Module for JBoss EAP

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="br.eti.fernandoribeiro.sample" slot="1.0">
  <main-class name="..."/>
  <properties>
    <property name="..." value="..."/>
    ...
  </properties>
  <resources>
    <resource-root path="..."/>
    ...
  </resources>
  <dependencies>
    <module name="..." />
    ...
  </dependencies>
</module>

You can find more details in the section 3.1.3 of the Development Guide.

How to Secure a JAX-WS Service with Basic Authentication in JBoss EAP

SampleService.java

import javax.jws.WebService;

@WebService
public class SampleService {
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>All web resources</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>SampleRole</role-name>
    </auth-constraint>
  </security-constraint>
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>SampleSecurityDomain</realm-name>
  </login-config>
  <security-role>
    <role-name>SampleRole</role-name>
  </security-role>
</web-app>

jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
  <security-domain>SampleSecurityDomain</security-domain>
</jboss-web>

How to Secure an EJB in JBoss EAP

SampleBean.java

import javax.annotation.security.RolesAllowed;
import javax.ejb.Stateless;

@RolesAllowed("SampleRole")
@Stateless
public class SampleBean {
}

jboss-ejb3.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss:ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jboss="http://www.jboss.com/xml/ns/javaee" xmlns:s="urn:security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd" impl-version="2.0" version="3.1">
  <assembly-descriptor>
    <s:security>
      <ejb-name>SampleBean</ejb-name>
      <s:security-domain>SampleSecurityDomain</s:security-domain> <!-- recommended over the SecurityDomain annotation -->
    </s:security>
  </assembly-descriptor>
</jboss:ejb-jar>

How to Setup Load Balancing in JBoss EAP with mod_jk

Domain Mode

1) Copy the <JBoss EAP Webserver Native Connector Install Dir>/modules/system/layers/base/native/lib64/httpd/modules/mod_jk.so file to the <Apache Install Dir>/modules directory.

2) Create the <Apache Install Dir>/conf.d/mod_jk.conf file:

LoadModule jk_module modules/mod_jk.so

JkMountFile conf/uriworkermap.properties

JkWorkersFile conf/workers.properties

<Location /jkstatus>
  JkMount status
</Location>

3) Create the <Apache Install Dir>/conf/uriworkermap.properties file:

/sample/*=loadbalancer

4) Create the <Apache Install Dir>/conf/workers.properties file:

worker.list=loadbalancer,status

worker.template.port=8009
worker.template.type=ajp13

worker.host1.reference=worker.template
worker.host1.host=host1

worker.host2.reference=worker.template
worker.host2.host=host2

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=host1,host2

worker.status.type=status

5) Add the jvmRoute system property to JBoss EAP:

/host=host1/system-property=jvmRoute/:add(value=host1)
/host=host2/system-property=jvmRoute/:add(value=host2)

6) Start Apache.

7) Start JBoss EAP.

Stand-Alone Mode

1) Copy the <JBoss EAP Webserver Native Connector Install Dir>/modules/system/layers/base/native/lib64/httpd/modules/mod_jk.so file to the <Apache Install Dir>/modules directory.

2) Create the <Apache Install Dir>/conf.d/mod_jk.conf file:

LoadModule jk_module modules/mod_jk.so

JkMountFile conf/uriworkermap.properties

JkWorkersFile conf/workers.properties

<Location /jkstatus>
  JkMount status
</Location>

3) Create the <Apache Install Dir>/conf/uriworkermap.properties file:

/sample/*=loadbalancer

4) Create the <Apache Install Dir>/conf/workers.properties file:

worker.list=loadbalancer,status

worker.template.port=8009
worker.template.type=ajp13

worker.host1.reference=worker.template
worker.host1.host=host1

worker.host2.reference=worker.template
worker.host2.host-host2

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=host1,host2

worker.status.type=status

5) Add the jvmRoute system property to JBoss EAP:

/system-property=jvmRoute/:add(value=host1)

6) Start Apache.

7) Start JBoss EAP.

You can find more details in the Administration and Configuration Guide.