Overloading CLASS files

G

gwoodhouse

Hello again,

In my application i'm using a .jar file to load classes of my webapp.
I assumed that i could drop a class file in the WEB-INF/classes/
directory using the same package structure and the webapp would
instead use the class file over the older version present in the jar.

It doesn't. Do any of you fine people know how to make it use the one
in classes over the one in the Jar? (And would this practice be
"overriding" the class in the Jar - is there a technical term for
this?)

Graeme
 
G

gwoodhouse

Hello again,

In my application i'm using a .jar file to load classes of my webapp.
I assumed that i could drop a class file in the WEB-INF/classes/
directory using the same package structure and the webapp would
instead use the class file over the older version present in the jar.

It doesn't. Do any of you fine people know how to make it use the one
in classes over the one in the Jar? (And would this practice be
"overriding" the class in the Jar - is there a technical term for
this?)

Graeme

As an addition to above -

I was thinking this may be to do with the order in which classes are
loaded? (Not sure on that point.)

If I added the location of the class file to the begining of the
CLASSPATH, would it mean it get's loaded first, stopping the one found
in the JAR being loaded?

Or would i add it to the end of the CLASSPATH, making sure that its
the last class to be looked at - therefore overwriting the namespace
of the class which is in the JAR file?

I've read here: http://www.onkarjoshi.com/blog/133/...erride-existing-java-class-files-temporarily/
you can place the class in the %JAVA_HOME%\lib\ext directory to make
this work, (I'd rather not), but is this a "special case" of where the
JVM looks for "higher priority" class files?

Graeme
 
G

gwoodhouse

Sorry,

This is turning into a running argument of solving my own problem it
seems as i've found this:

http://tomcat.apache.org/tomcat-4.1-doc/class-loader-howto.html
"Therefore, from the perspective of a web application, class or
resource loading looks in the following repositories, in this order:

* /WEB-INF/classes of your web application
* /WEB-INF/lib/*.jar of your web application
* Bootstrap classes of your JVM
* System class loader classses (described above)
* $CATALINA_HOME/common/classes
* $CATALINA_HOME/common/endorsed/*.jar
* $CATALINA_HOME/common/lib/*.jar
* $CATALINA_BASE/shared/classes
* $CATALINA_BASE/shared/lib/*.jar"

So, from my understanding, having a file here:
WEB-INF/classes/uk/co/site/www/File.class

should load before:
WEB-INF/lib/jar.jar which contains uk/co/site/www/File.class

.... Shouldn't it? ARG!
 
M

markspace

So, from my understanding, having a file here:
should load before:
.... Shouldn't it? ARG!


I've seen some containers retain classes in memory between deployments.
For example, when debugging I like to configure local loggers myself
in code and add a ConsoleHandler so I can see output. Well after
redeploy the app I noticed that the console debug lines doubled, then
after the next deployment they tripled, etc.

Turns out the Logger was being held in memory between deployments, and
each time I ran I added a ConsoleHandler to a logger that already had
one, so I was seeing additional lines of text from the extra
ConsoleHandlers.

Not sure if your problem is related. Just saying to consider all
possibilities. Can you verify a new class (the other one) is loaded
fresh each time? Are you sure you've spelled the name and path
correctly in WEB-INF/classes/... correctly? Etc.

Good luck, I haven't tried to do exactly what you're doing myself, but I
do read the documentation the same as you.
 
A

Arne Vajhøj

In my application i'm using a .jar file to load classes of my webapp.
I assumed that i could drop a class file in the WEB-INF/classes/
directory using the same package structure and the webapp would
instead use the class file over the older version present in the jar.

It doesn't. Do any of you fine people know how to make it use the one
in classes over the one in the Jar? (And would this practice be
"overriding" the class in the Jar - is there a technical term for
this?)

You will need to restart the app anyway so why not just replace
the jar file itself?

Arne
 
A

Arne Vajhøj

I've seen some containers retain classes in memory between deployments.
For example, when debugging I like to configure local loggers myself in
code and add a ConsoleHandler so I can see output. Well after redeploy
the app I noticed that the console debug lines doubled, then after the
next deployment they tripled, etc.

Turns out the Logger was being held in memory between deployments, and
each time I ran I added a ConsoleHandler to a logger that already had
one, so I was seeing additional lines of text from the extra
ConsoleHandlers.

Stuff like that does not happen by magic. There must be a reason.

Most likely in this case that some of the involved classes were
loaded by a server classloader instead of the app classloader, so
static stuff were not unloaded with the app.

Arne
 
L

Lew

You will need to restart the app anyway so why not just replace
the jar file itself?

Having more than one source of the same class in the same app is a recipe for
disaster, especially for web and enterprise apps. Don't do it.

I've been on several projects where multiple versions of the same class, or
even the same JAR, or even the identical JAR more than once, got loaded. It
causes interesting consequences, like class-cast exceptions when assigning an
instance of a type to a variable of its supertype.

Then you get into production and code that depends on the offending class or
JAR starts fubaring because it can't get to the version it expects, or they're
coming in via different classloaders.

Just don't do it.
 

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,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top