Dynamic class reloading problems

15 views
Skip to first unread message

Ilya.ufo

unread,
Sep 26, 2010, 8:47:49 AM9/26/10
to Induction Framework
Hi, everybody!
Please help me with the following issue!

We decided to try feature with dynamic class reloading. So download
library, sample sources and make project in IDEA. Set up java-class-
path in induction-demoapp.xml like

<java-class-path>
<compiled-directory>
<directory>c:/private/java/web/induction-demo/out/
artifacts/induction_demo_war_exploded/WEB-INF/classes</directory>
</compiled-directory>
</java-class-path>

The project normally compliled, deployed and worked. When i change
outputed string in HelloWorld1Controller.java from, for example,
"hello world" to "hi, there" i see that corresponding class changed
but after reloading the page it is still contains old string.

Have any idea what i did wrong?

And one more minor question...When reload application (for example
from tomcat admin interface) in the log appears the following text

INFO: Undeploying context [/induction-demo]
26.09.2010 16:30:51 org.apache.catalina.loader.WebappClassLoader
clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type
[com.acciente.commons.loader.ReloadingClassLoader.ClassNameSet] (value
[com.acciente.commons.loader.ReloadingClassLoader
$ClassNameSet@54140fee]) and a value of type [java.util.HashSet]
(value [[]]) but failed to remove it when the web application was
stopped. To prevent a memory leak, the ThreadLocal has been forcibly
removed.

Is it ok?

Thanks,
Ilya

DavidNia

unread,
Sep 27, 2010, 1:22:15 PM9/27/10
to Induction Framework
This might be obvious, but make sure that the class file under c:/
private/java/web/induction-demo/out/
artifacts/induction_demo_war_exploded/WEB-INF/classes has been
changed.

IDEA might be placing compiled class files in a few temporary places
before it finds its way in the exploded directory, so make sure you
are checking the final directory that induction is looking.

Also make sure the induction.xml that is *deployed* (not the one you
edit and perhaps is in your source directory) has the proper
configuration you expect.

Now, assuming everything checks out ok, once you recompile and you
still see the old string, what happens when you restart tomcat
*without* re-deploying...do you still see the old string or new
string?

If you restart and still see the old string, perhaps the class file is
not going where you think it is. But if a restart shows the new
string, then something is misconfigured with the induction reloading.

david

Adi

unread,
Sep 27, 2010, 1:22:31 PM9/27/10
to Induction Framework
Hi Ilya,

I think I see what the issue is, you are pointing Induction at the the
directory for the .war file, this is incorrect. The correct way to do
it is as follows:

1) Make sure to setup the IDEA artifact to NOT include your
application classes in the .war file (i.e. it should NOT go in c:/
private/java/web/induction-demo/out/artifacts/
induction_demo_war_exploded/WEB-INF/classes)

2) Next point Induction directly to where your class compiled output
goes. For example it could be c:/private/java/web/induction-demo/out/
classes or something

For example it would look like:

<java-class-path>
<compiled-directory>
<directory>c:/private/java/web/induction-demo/out/
classes</directory>
</compiled-directory>
</java-class-path>

3) It's ok to put stuff you don't need to be reloaded in c:/private/
java/web/induction-demo/out/artifacts/induction_demo_war_exploded/WEB-
INF/classes

This should fix your issue. You should be able to to now just compile
in IDEA (using Ctrl-Shift-F9) and hit F5 on the browser!

> And one more minor question...When reload application (for example
> from tomcat admin interface) in the log appears the following text
>
> INFO: Undeploying context [/induction-demo]
> 26.09.2010 16:30:51 org.apache.catalina.loader.WebappClassLoader
> clearThreadLocalMap
> SEVERE: A web application created a ThreadLocal with key of type
> [com.acciente.commons.loader.ReloadingClassLoader.ClassNameSet] (value
> [com.acciente.commons.loader.ReloadingClassLoader
> $ClassNameSet@54140fee]) and a value of type [java.util.HashSet]
> (value [[]]) but failed to remove it when the web application was
> stopped. To prevent a memory leak, the ThreadLocal has been forcibly
> removed.

You don't need to worry about this as far as I know.

Adi

Ilya.ufo

unread,
Sep 27, 2010, 2:23:20 PM9/27/10
to Induction Framework
Thank you Adi and DavidNia very much!
The problem was in that classes were loaded by WebappClassLoader
instead ReloadingClassLoader. When i changed the place where classes
had been compiled from WEB-INF/classes to WEB-INF/classes2 it began to
work fine!

One more question had arised while i was experimenting with Induction.
As far as i understood it's reload only View or Controller classes. Is
there the opportunity to make Induction reload my arbitrary class (for
example, some service class)?

DavidNia

unread,
Sep 27, 2010, 2:35:24 PM9/27/10
to Induction Framework
> Thank you Adi and DavidNia very much!

You're very welcome.

> One more question had arised while i was experimenting with Induction.
> As far as i understood it's reload only View or Controller classes. Is
> there the opportunity to make Induction reload my arbitrary class (for
> example, some service class)?

It reloads Model classes too, but depending on the state of your
session (ie. whether there are references to instantiated objects) you
may need to either restart your session or tomcat all together.

I can't answer any further than this...dynamic class reloading can be
a difficult topic.

david
Reply all
Reply to author
Forward
0 new messages