Skip to content

Deploying with WebLogic

Julian Cheal edited this page Oct 13, 2015 · 4 revisions

Oracle WebLogic Server 11g (and possibly other older versions) require a bit of tuning to deploy JRuby-Rack applications.

We'll set the required configuration in WebLogic's proprietary deployment descriptor weblogic.xml :

<!-- since WL 12 the XML name-space changed, make sure you use the correct one :
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">-->
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
  <container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
    <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
  </container-descriptor>
</weblogic-web-app>

According to some, this seems to not always work e.g. with WebLogic Server 12.1.3.0.0, another way is the fine tune what packages the class-loader prefers explicitly :

<?xml version="1.0" encoding="UTF-8"?>
<!-- this should work with anything >= WL 10.3, make sure your xmlns is right
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">-->
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
  <container-descriptor>
    <prefer-web-inf-classes>false</prefer-web-inf-classes>
    <prefer-application-packages>
      <package-name>org.joda.*</package-name>
      <package-name>org.jruby.*</package-name>
    </prefer-application-packages>
    <!--
    <prefer-application-resources>
      <resource-name>META-INF/jruby.home</resource-name>
    </prefer-application-resources>-->
  </container-descriptor>
  <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</weblogic-web-app>

If you're using Warbler to package up your application into a .war create config/weblogic.xml and copy the above content into it. Than update config/warble.rb to include this file into the archive's WEB-INF directory :

Warbler::Config.new do |config|
  # ...

  # Files for WEB-INF directory (next to web.xml). This contains
  # web.xml by default. If there is an .erb-File it will be processed
  # with webxml-config. You may want to exclude this file via
  # config.excludes.
  config.webinf_files += FileList["config/weblogic.xml"]

  # ...
end

Explanation

  • prefer-web-inf-classes makes sure your application java classes (e.g. packaged in .jar files) are preferred over the server classes. This avoids class collisions e.g. if JRuby uses the same library as the container but with a different version (they both use JodaTime - without this your deployment might end up with exceptions such as a missing withYear method on org.joda.time.DateTime or no method 'getInstance' for arguments (org.joda.time.tz.CachedDateTimeZone) on Java::OrgJodaTimeChrono::GJChronology). A value specified in the Administration Console will take precedence over a value set manually!

  • prefer-application-packages it is very similar to the above, except it allows to specify a list of packages (for Java classes) that must always be loaded from the application (e.g. WEB-INF/lib/*.jar files)

  • show-archived-real-path-enabled enables the use of ServletContext.getRealPath method to map packaged files into FS paths, this is not strictly required as JRuby-Rack has some workarounds but should not hurt.

Clone this wiki locally