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
My finding was 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 the test class:
public class TestFooInWeb/TestFoo {
@Test
public void testHello() {
System.out.println(new Foo().sayHello());
}
@Test
public void testHelloFromBar() {
new Bar().sayHelloForFoo();
}
}
So all at the end, I stand corrected. You apprantly can load a completely different class and all Jar files will use that new class. This makes sense because the ClassLoader
will first look at the classes directory. I am not sure if I agree with it because it sounds suspicious and I can overwrite security classes.