Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put a shared library in JBoss AS 5?

I m new to Jboss, but I have multiple web applications each using spring-hibernate and other open source libraries and portlets, so basically now each war file includes those jar files. How do I move these jars to a common location so that I don't have to put these in each war file? I guess location is server/default/lib, but I'm not sure.

Also, how is it different to have those jars at WEB-INF/lib vs. JBOSS/server/default/lib? Will I face any classloader issue?

Also I have static data stored in static fields like Singleton, will those be shared across all WAR files?

like image 315
Tushar Khairnar Avatar asked Jan 21 '10 11:01

Tushar Khairnar


People also ask

Where is JBoss configuration file?

The default JBoss configuration file set is located in the JBOSS_DIST/server/default directory. JBoss allows you to add more than one configuration set so a server can easily be run using alternate configurations.

What are the main directories provided in JBoss?

In Figure 3.1, “The JBoss AS directory structure”, the default server configuration file set is shown expanded. It contains a number of subdirectories: conf, data, deploy, lib, log, and tmp. In a clean installation, only the conf, deploy, and lib directories will exist.

Can we deploy jar file in JBoss?

It's possible to deploy EJB-jar files directly in Jboss (jar extension), if they follow the EJB packaging model (you don't need to place it in an ear necessarily).


2 Answers

Classloading:

You're right, put the .jars to JBOSS/server/<configuration>/lib, or JBOSS/lib.

JBoss AS comes with bundled Hibernate libs which are tested with that AS version.

See jboss-6.0.0-SNAPSHOT\server\default\conf\jboss-service.xml:

<server>
  <!-- Load all jars from the JBOSS_HOME/server/<config>/lib directory and
       the shared JBOSS_HOME/common/lib directory. This can be restricted to
       specific jars by specifying them in the archives attribute.
       TODO: Move this configuration elsewhere
  -->
  <classpath codebase="${jboss.server.lib.url}" archives="*"/>
  <classpath codebase="${jboss.common.lib.url}" archives="*"/>
</server>

Also see:

  • http://community.jboss.org/wiki/classloadingconfiguration
  • http://community.jboss.org/wiki/JbossClassLoadingUseCases

Difference between WEB-INF/lib and JBOSS/server/default/lib:

Libs in WEB/lib come with your WAR and are only visible within that WAR. If you have other module, e.g. EJB JAR, they will not be visible from it and you'll get ClassNotFoundException or (if you have the class in multiple places) ClassCastException.

Libs in JBOSS-AS/server/<config>/lib are visible for whole server, thus all deployed apps and their modules. However (IIRC) they don't have precedence, so if you bring that lib e.g. in a WAR, but not in EJB jar, you can end up using two different versions, which is undesirable (will likely lead to aforementioned ClassCastException).

Class loading behavior may be tweaked several ways, see e.g. JBoss wiki.

Static data:

Don't rely on static fields in Java EE, that brings troubles. For instance,. the same class can be loaded by different classloaders, so there will be multiple instances of these static values.
If you want to share data amongst more WARs, use an external storage - a database, a file (with synchronization if you write to it), JBoss Cache, etc.

like image 93
Ondra Žižka Avatar answered Oct 27 '22 13:10

Ondra Žižka


http://www.mastertheboss.com/en/jboss-server/211-configuring-jboss-shared-libs.html

like image 40
Vit Avatar answered Oct 27 '22 12:10

Vit