• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

When the project is running a class file that can be added?

 
Greenhorn
Posts: 13
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

When the project is running a class file that can be added?

Runtime I want to add a class files to the project, almost like adding another component.

Help me.
 
Ranch Hand
Posts: 133
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What project are you talking about?

Please provide technical details, so that you can get help.

Also, how about using Please help me?
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure about individual class files - it's exceedingly rare that web apps use loose class files, everything is generally packaged in jar files. Jar files you can not add at runtime - Tomcat (and I would guess other servlet containers as well) reads those at startup time, so they can't be added later.

What is the exact requirement you're trying to address? The high.end approach to dynamic classloading -and even replacing classes at runtime- is OSGi.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does "project is running" mean you are using some sort of IDE to execute Tomcat? It is important to describe the environment you are working in.
 
Saloon Keeper
Posts: 21708
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:I'm not sure about individual class files - it's exceedingly rare that web apps use loose class files, everything is generally packaged in jar files. Jar files you can not add at runtime - Tomcat (and I would guess other servlet containers as well) reads those at startup time, so they can't be added later.

What is the exact requirement you're trying to address? The high.end approach to dynamic classloading -and even replacing classes at runtime- is OSGi.



Actually, Tomcat (hence JBoss and Jonas), WebSphere, and WebLogic all support "exploded" WARs - directories that contain the unzipped files from a WAR. This is an extension to J2EE, so one should never write code that considers that sort of deployment normal (unless you're writing server-specific deployment code), and - as I've said many times - one should absolutely positively NEVER use that as a justification for a webapp to write data files into its own WAR.

In the case of Tomcat, deployed exploded WARs are scanned periodically for changes. The interval is a configurable value. If a WAR has changed, Tomcat will dynamically accept the changes.

There are some limits. Static initializations will generally not be done again. PermGen space will almost never be freed (and you'll soon run out). Warranties void where prohibited. And so forth. But it can be done in many cases. For example, in servlets without init() methods.

Note that the scanning isn't restricted to webapps dumped into TOMCAT/webapps directory. I build my exploded WAR as a prototype in the project source directory (the actual WAR file is zipped from there). I have a Context file in TOMCAT_HOME/conf/Catalina/localhost pointing to it. So I can do on-the-fly mods to the project and have them picked up, subject to the limitations I listed previously.
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:In the case of Tomcat, deployed exploded WARs are scanned periodically for changes. The interval is a configurable value. If a WAR has changed, Tomcat will dynamically accept the changes.


But that will cause the entire context (i.e., web app) to be reloaded - I don't think that's what amir is asking about. Or at least it doesn't sound like that would be desirable :-)
 
Tim Holloway
Saloon Keeper
Posts: 21708
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to make limited-scope changes to an application, it's going to need some way of defining what that scope is. For OSGi, that would be an OSGi component. For a J2EE-compliant webapp, the smallest component is a WAR, JAR (EJBS), or similar archive. Which in the case of Tomcat, means WAR, since that's all it supports.

If a WAR wants to alter its internal structure on a fractional basis, it will have to do so itself - implement itself as an OSGi container or something similar (custom classloaders). From the perspective of Tomcat, the WAR is a single unit.
 
amir kawaja
Greenhorn
Posts: 13
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

rohit chavan wrote:What project are you talking about?

Please provide technical details, so that you can get help.

Also, how about using Please help me?


I've made a small CMS. I want to add the component. The structure of 1-jsp files 2 -class files 3 - css, js ,... files
 
amir kawaja
Greenhorn
Posts: 13
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William Brogden wrote:Does "project is running" mean you are using some sort of IDE to execute Tomcat? It is important to describe the environment you are working in.



no. Tomcat is running on a real host .
 
amir kawaja
Greenhorn
Posts: 13
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:

Tim Holloway wrote:In the case of Tomcat, deployed exploded WARs are scanned periodically for changes. The interval is a configurable value. If a WAR has changed, Tomcat will dynamically accept the changes.


But that will cause the entire context (i.e., web app) to be reloaded - I don't think that's what amir is asking about. Or at least it doesn't sound like that would be desirable :-)


thanks. How to prevent reloaded entire context ?
 
Tim Holloway
Saloon Keeper
Posts: 21708
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reloading the context is part of the J2EE contract.

If you want a CMS that supports dynamic sub-contexts, you're either going to have to manually create one yourself or adopt a pre-written/pre-debugged framework such as Portlets (JSR-288 and its heirs).
 
Marshal
Posts: 25134
64
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general it isn't possible to take a running JVM and tell it to use a new version of a class. If you consider the ramifications, such as having instances of the old version and instances of the new version active simultaneously, you might see why that is. However with clever use of class loaders it's possible to do it in restricted ways, such as the ones Tim described in his post about "scope".

But in general, if you need to install an updated version of a class then you're going to have to restart the web app.
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!