Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Overloading CLASS files

Reply
Thread Tools

Overloading CLASS files

 
 
gwoodhouse@gmail.com
Guest
Posts: n/a
 
      09-27-2010
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
 
Reply With Quote
 
 
 
 
gwoodhouse@gmail.com
Guest
Posts: n/a
 
      09-27-2010
On Sep 27, 2:21*pm, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> 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/h...s-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
 
Reply With Quote
 
 
 
 
gwoodhouse@gmail.com
Guest
Posts: n/a
 
      09-27-2010
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-...der-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!






 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      09-27-2010
On 9/27/2010 6:46 AM, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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.

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-27-2010
On 27-09-2010 09:21, (E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-27-2010
On 27-09-2010 13:35, markspace wrote:
> 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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-28-2010
On 09/27/2010 06:36 PM, Arne Vajh├Şj wrote:
> On 27-09-2010 09:21, (E-Mail Removed) wrote:
>> 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?


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.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Overloading __init__ & Function overloading Iyer, Prasad C Python 4 09-30-2005 08:01 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 03:59 PM
Overloading __init__ & Function overloading Iyer, Prasad C Python 3 09-30-2005 02:17 PM
Re: Overloading __init__ & Function overloading Steve Holden Python 0 09-30-2005 01:58 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 01:53 PM



Advertisments