Monday, April 16, 2012

JBoss 7 & Sandbox

JBoss 7 AS, has modular class loading. It provides true application isolation, hiding server implementation classes from application and only loading the classes your application needs. Modules, packaged as collections of classes, are peers that remain isolated unless explicitly defined as a dependency of another module. These visibility rules  can be customized. 

Due to this design, JBoss modules does not load everything from rt.jar and many other system jars by default. As a result you may get ClassNotFoundException or NoClassDefFounfError for a lot of classes. 

Example: 
com.sun.imageio.*
javax.annotation.processing.*
com.aqua.LookAndFeel
Open Office, web services tests might fail

Solution: jboss-deployment-structure.xml  -

To Fix this the solution is to, use a jboss-deployment-structure.xml in your war as explained here https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

Example:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
         <module name="deployment.system"/>
        </dependencies>
    </deployment>
    <module name="deployment.system">
     <dependencies>
         <system export="true">
             <paths>
                 <path name="com/sun/net/ssl/internal/ssl"/>
             </paths>
         </system>
     </dependencies>
    </module>
</jboss-deployment-structure>


However if for some reason you can't add jboss-deployment-structure.xml quickly in your application following are 2 workarounds.

Workarounds 1: For JRE System classes, There is a modue named "sun.jdk" that depdends on module "system". Here are defined all packages jboss loads from rt.jar.

In this module.xml of /sun/jdk/main directory add the required packages as -
                        <path name="com/sun/imageio/spi"/>
                        <path name="javax/annotation/processing"/>
etc, according to the need of application.

Example:
<module xmlns="urn:jboss:module:1.0" name="sun.jdk">
    <resources>
        <resource-root path="service-loader-resources"/>
    </resources>
    <dependencies>
        <module name="system" export="false" services="import">
            <exports>
                <include-set>

                    <!-- extra packages -->
                    <path name="javax/annotation/processing"/>

                    <path name="com/sun/script/javascript"/>
                    <path name="com/sun/imageio/spi"/>
                    <path name="com/sun/jndi/dns"/>
                    <path name="com/sun/jndi/ldap"/>
                    <path name="com/sun/security/auth"/>
                    <path name="com/sun/security/auth/module"/>
                    <path name="sun/misc"/>
                    <path name="sun/nio"/>
                    <path name="sun/nio/ch"/>
                    <path name="sun/util"/>
                    <path name="sun/util/calendar"/>
                    <path name="META-INF/services"/>
                </include-set>
            </exports>
        </module>
    </dependencies>
</module>

Workaround 2:

Add jboss.modules.system.pkgs system property with comma separated list of packages to load. 

-Djboss.modules.system.pkgs=com.sun.imageio.spi,javax.annotation.processing

Additional Information:

Related issues - 

JBoss cfusion.ear/war deployment timeout:

If cfusion.ear is not deployed within the deployment timeout for jboss you can change the deployment timeout of jboss in standalone.xml
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.0">
   <deployment-scanner scan-interval="5000"
      relative-to="jboss.server.base.dir" path="deployments"   deployment-timeout=”120”,/>
</subsystem>

Profiling:

Performance tuning is an important part any application development.  In order to use JProfiler ofor jboss 7, first you need to add the following to your standalone.conf file:

JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=com.jprofiler -agentlib:jprofilerti -Xbootclasspath/a:/path/to/jprofiler/bin/agent.jar"

The "jboss.modules.system.pkgs" property tells JBoss Modules to allow the "com.profiler" classes to be found from any class loader, which is essential to allow the JProfiler agent to run. It is easier to then just set up your jprofiler sessio nas "Remote", and start the server and profiler.

2 comments:

  1. Have you taken a look at what it takes to deploy CF 11 on the latest community edition of Jboss, WildFly 8?

    I'm having class load errors there within the admin module. The navigation menu won't load.


    Class not found: com.adobe.coldfusion.entman.ProcessServer
    The error occurred in navserver.cfm: line 145
    Called from navserver.cfm: line 101
    Called from navserver.cfm: line 1
    Called from navserver.cfm: line 145

    ReplyDelete
  2. Thanks a lot for the hint! Workaround 1 worked for my case

    ReplyDelete

You can subscribe to the comments by licking on "Subscribe by email".