• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding a jar without touching existing code  RSS feed

 
John Landon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I do not think this question is related to tomcat. This is a general question but still I will give you the details.
My system is a web application runs under tomcat (but even if it wasn't). How do I add a jar (that can extend one of already existing classes in the core code) and just return the system and the jar will be taken into account like if it was part of the core code?

Thanks ahead!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not real clear on what you are trying to do.

IF the code now runs without a problem
THEN Tomcat knows where to find all the jars it needs. Why would it need to look for the classes in your jar?

Do you want to replace an existing Jar library? If so you need to figure out where Tomcat is currently finding that library.

Are we talking about a custom ClassLoader here?

Bill
 
John Landon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think my question here is lets say I have class Sum that lets say can summarize 2 numbers.
I compile it and run it. So now it's running and you can use it (let’s say I have a GUI for that). Now I want to have another utility that does multiplication let’s say class Mult. So I want the class Mult extent the class Sum to use the latest for multiplication. But I do not want to recompile class Sum. I want to have a jar with the class Mult (and it’s gui) and just run it. Do you understand what I mean now?
Thanks.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I want the class Mult extent the class Sum

This sounds odd from a functional point of view. I think it would be more likely that all operations implement a common interface, maybe something like "public double op (double[])", assuming that the operations can have an arbitrary number of parameters, and return a single result value.

What you can easily do is to drop a new class file in your WEB-INF/classes directory. That would be picked up dynamically by the servlet container (you couldn't replace a class file with a newer version, though).

With jar files it's more complicated, because some containers read and cache those at application startup (in which case adding any jar files later has no impact).

It gets more complicated if you need to update these services (or plugins, or whatever you want to call them) at runtime. Then you'd either be looking at a home-grown solution using ClassLoaders (which I would advise against), or running an embedded OSGi container like Apache Felix (which has a certain learning curve, but is not real bad).
 
John Landon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"With jar files it's more complicated, because some containers read and cache those at application startup (in which case adding any jar files later has no impact). "

That's exactly what I need! And I DO want to restart the app. So how do you do it?

 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,

Just like simple Java apps having classpaths, where they look for class files, webaps too have classpaths. That is not to say that they override the usual java classpath, but in addition to the java classpath, a web application container, like tomcat has folders where it will look for class files [and jar files] at runtime. Now, I'm not too familiar with all web containers, but lets say, we take the case of tomcat. In tomcat, there is a folder "<tomcat_root>/lib" which holds the jar files which can be used at runtime for all web applications being hosted in that tomcat instance.... Or if you need this jar only for your application, then you can place it in "<tomcat_root>/webapps/<your_app_name>/WEB-INF/lib"

So, coming to the point, you can always place your jar file in this folder, restart the container, and tomcat will pick it up alright.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Individual web applications can be restarted without disturbing the other contained applications using Tomcats Management App - a separate download not part of the standard distribution.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!