views:

679

answers:

4

I have a project built and packaged with a specific version of jsp-apiand servlet-api jar files. Now I want these jars to be loaded when deploying the web project on any application server for example tomcat, WAS, Weblogic etc.

The behaviour I have seen on tomcat is that it gives messages that the packaged version of these apis are not loaded along with an offending class.

Is there any way I could override these server settings or behaviour?

My concern is that letting the default behaviour of a server may allow different behaviour on different servers or even on different versions of same app server.

+2  A: 
  1. If you have control over the server where you want to install this webapp you can replace the core jars with yours.
  2. Additionally you can prepend the jars in the startup of the app server.

Update:

As for the second part, you'll need to modify the startup file of the application server it self.

I don't have an installation at hand but lets suppose in the dir $YOUR_APPSERV/bin there are a bunch of scripts ( either .cmd or .sh files )

Some of them start the app server , some other help to configure it.

You need to modify one of those in such a way the command line look like this:

(assume a windows installation)

java -Xbootclasspath/p:c:\cutomjars\myJar.jar;customjars\myOtherJar.jar ..................... // the rest of the normal command line.

-bootclasspath/p prepends the jars to the app classpath

-bootclasspath/a appends the jars to the app claspath

This option let you override any class in the JVM with those specified in the jars, so you can even substitute java.lang.String if you want to.

That's one approach. Unfortunately -Xbootclasspath is an option for Sun JVM ( that is JRockit does not have it, nor the IBM's VM what ever his name is )

There was another option where you declare a folder where all the extensions are. Plus, there is an ext directory in the jre.

Take a deep dive into your application server bin directory and find out what each script is used for, I'm pretty sure you'll make it through.

Here's a more formal explanation of this topic: http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html

I hope it helps.

BTW, I use to do this years ago, to substitue the CORBA package with a veeeery old version. So this works for sure.

OscarRyz
Can you elaborate a bit on this? I wouldn't want to replace any server jars.
Tushu
On the second you mean? Sure.
OscarRyz
I have not been successful to achieve the result either ways till date.
Tushu
Can you post some links to the jars in question, also which servlet container do you have?
OscarRyz
The above versions of jar files have been downloaded from maven repository.
Tushu
I have servlet-api-2.4.jar and jsp-api-2.0.jar files in my web application package. The servlet container in question is Tomcat-6.0.18 as you used in your example below. I agree with your approach of jar loading at bootstrap but is there any way out if anyway I try to stick with my own versions?
Tushu
Both JRockit and IBM have a -Xbootclasspath option.
staffan
A: 

JRockit can use -Xbootclasspath. See the command line reference

Kire Haglin
+1  A: 
OscarRyz
A: 

Other option is to use

-Djava.endorsed.dirs

Upon JVM startup

OscarRyz