Loading Two Different Versions of the Same Class/JAR???

J

John Davison

I'm trying to write an application that runs on an app server. The app
server uses an older version of a particular API. In my application I
need to use a newer version of the same API. If I put the JAR
containing the newer version of the API in my app server's classpath,
the app server fails. How do I load my own copy of this JAR?

-- John
 
M

Michael Borgwardt

John said:
I'm trying to write an application that runs on an app server. The app
server uses an older version of a particular API. In my application I
need to use a newer version of the same API. If I put the JAR
containing the newer version of the API in my app server's classpath,
the app server fails. How do I load my own copy of this JAR?

Use an URLClassLoader.
 
A

Amitabh

I'm trying to write an application that runs on an app server. The app
server uses an older version of a particular API. In my application I
need to use a newer version of the same API. If I put the JAR
containing the newer version of the API in my app server's classpath,
the app server fails. How do I load my own copy of this JAR?

-- John

Hi John,

You should'nt add your application specific jar in the apps server
classpath. Most app server provide a method to include the jar file
only for the context of your application. Usually (at least in tomcat)
you put the jar file in WEB-INF/lib directory of your context. In
tomcat if you want to use a jar across multiple contexts, the place to
put the jar is $CATALINA_TOP/shared/lib.

If this does not help, then the only way out would be to write your
own ClassLoader and load the target classes and all other classes that
use them through this ClassLoader. But this method has its own
disadvantages. You will loose the benifits, like dynamic reloading
etc, that the apps server ClassLoader would provide you.

Regards

Amitabh
 
A

Amitabh

I'm trying to write an application that runs on an app server. The app
server uses an older version of a particular API. In my application I
need to use a newer version of the same API. If I put the JAR
containing the newer version of the API in my app server's classpath,
the app server fails. How do I load my own copy of this JAR?

-- John

Hi John,

You should'nt add your application specific jar in the apps server
classpath. Most app server provide a method to include the jar file
only for the context of your application. Usually (at least in tomcat)
you put the jar file in WEB-INF/lib directory of your context. In
tomcat if you want to use a jar across multiple contexts, the place to
put the jar is $CATALINA_TOP/shared/lib.

If this does not help, then the only way out would be to write your
own ClassLoader and load the target classes and all other classes that
use them through this ClassLoader. But this method has its own
disadvantages. You will loose the benifits, like dynamic reloading
etc, that the apps server ClassLoader would provide you.

Regards

Amitabh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top