So there is only one way to find out. I wrote a test :)
├── example │ ├── example.iml │ ├── pom.xml │ └── src │ ├── main │ │ └── java │ │ └── test │ │ ├── Bar.java │ │ └── Foo.java │ └── test │ └── java │ └── testexample │ └── TestFoo.java ├── pom.xml ├── test.iml └── web ├── pom.xml ├── src │ ├── main │ │ └── java │ │ └── test │ │ └── Foo.java │ └── test │ └── java │ └── junittest │ └── TestFooInWeb.java └── web.iml 16 directories, 11 files
I found that in TestFoo.java prints
Hello from example.jar Hello from example.jar
And for TestFooInWeb.java prints
Hello from web app Hello from web app
Both tests have this in a test class:
public class TestFooInWeb/TestFoo { @Test public void testHello() { System.out.println(new Foo().sayHello()); } @Test public void testHelloFromBar() { new Bar().sayHelloForFoo(); } }
So, everything is at the end, I stand fixed. You can load a completely different class, and all Jar files will use this new class. This makes sense because ClassLoader first look at the class directory. I am not sure if I agree with this because it sounds suspicious and I can overwrite security classes.
Amir raminfar
source share