Re: ClassLoader not loading recompiled classes
- From: Silvio Bierman <sbierman@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 02 Oct 2007 13:29:00 +0200
Aryeh M. Friedman wrote:
On Oct 2, 9:28 am, Silvio Bierman <sbier...@xxxxxxxxxxxxxxxxxx> wrote:Aryeh M. Friedman wrote:On Oct 2, 7:56 am, Silvio Bierman <sbier...@xxxxxxxxxxxxxxxxxx> wrote:Is there any need to run the tests in-process? You could spawn anAryeh M. Friedman wrote:I wrote a gui based unit testing framework and it loads the top levelOn Oct 2, 6:02 am, Daniel Pitts <googlegrou...@xxxxxxxxxxxxx> wrote:You don't. You can write your own class loaders if you want and canOn Oct 1, 10:53 pm, "Aryeh M. Friedman" <Aryeh.Fried...@xxxxxxxxx>Since I am relativally naive with class loaders how do I create a new
wrote:
ClassLoader does not update class on recompile:Right, a ClassLoader will not re-load a class. You will have to
Script started on Tue Oct 2 01:45:20 200> cat Main.java
public class Main
{
public static void main(String[] args)
throws Throwable
{
while(true) {
ClassLoader loader=ClassLoader.getSystemClassLoader();
Class klass=loader.loadClass("MyClass");
MyClass mc=(MyClass) klass.newInstance();
System.out.println("hit any key to reload/rerun MyClass");
System.in.read();
}
}}
cat MyClass.javapublic class MyClass
{
public MyClass()
{
System.out.println("not hi there");
}}
javac *.javanot hi there
java Main
hit any key to reload/rerun MyClass
not hi there
hit any key to reload/rerun MyClass
^Z
Suspended> cat foo
public class MyClass
{
public MyClass()
{
System.out.println("foo on you");
}}
mv foo MyClass.javajava Main
javac MyClass.java
fg
not hi there
hit any key to reload/rerun MyClass
^C> exit
Script done on Tue Oct 2 01:47:02 200
instantiate a new class loader to do so.
ClassLoader.loadClass will first look for already loaded classes. It
will not re-load the class into the JVM.
Its generally difficult to get dynamic class behavior from Java. You
aren't able to unload a class, and load a different version of it.
Also, and already loaded classes that refer to that other class will
only be able to refer to one instance of it, not one from one class
loader, and then another from another class loader.
instance of the system class loader?
implement any loading behavior you think is suitable.
Beware that class-reloading introduces all kinds of behavior that is
counter-intuitive. Multiple instances of what appears to be the same
static variable thereby also breaking singleton patterns in your code
(which are broken already, but that is a completely different matter) is
only one example.
Please start by telling us what the real problem is that you need to
solve. Going the class-loader way is probably among the worst solutions
for your problem.
test suites from a text box with there names in it (initially
populated from command line)... I do not want to have to close/reopen
the app when I rewrite/recompile some code under test.
--Aryeh
external java process to run the tests and have it store the test
results in a place where the GUI can find it.
Gr.
Silvio
In theory no but it sounds a little kludgist and perhaps not portable
(I don't see how it wouldn't be but once you ask the OS for anything I
get nervious)
For this kind of application the ClassLoader woes I mentioned are probably not relevant. However, you must remember that when you run such completely generic test code in-process you may (and probably will) compromise the state of your VM and risk bringing down the application itself.
I would go the out-of-process way. I do not see why this would not work in any reasonable Java Runtime env.
Regards,
Silvio
.
- References:
- ClassLoader not loading recompiled classes
- From: Aryeh M. Friedman
- Re: ClassLoader not loading recompiled classes
- From: Daniel Pitts
- Re: ClassLoader not loading recompiled classes
- From: Aryeh M. Friedman
- Re: ClassLoader not loading recompiled classes
- From: Silvio Bierman
- Re: ClassLoader not loading recompiled classes
- From: Aryeh M. Friedman
- Re: ClassLoader not loading recompiled classes
- From: Silvio Bierman
- Re: ClassLoader not loading recompiled classes
- From: Aryeh M. Friedman
- ClassLoader not loading recompiled classes
- Prev by Date: Wholesale all NIKE.shox.Air max.AF1.TN.Jordan.shoes.Apple Ipods Nano, Xbox 360, Sony PS3, Sony PSP.wii.all laptops http://www.new-nikeshoes.com
- Next by Date: BufferedReader.readLine() blocks unexpected
- Previous by thread: Re: ClassLoader not loading recompiled classes
- Next by thread: Re: ClassLoader not loading recompiled classes
- Index(es):
Relevant Pages
|