0

I'm wonder what would happen, if I have an application with couple ears and wars, and in each of them class named "Test"? Is it jar hell? What classes would load first (from ears or from wars)? Please, send me somewhere, where I can read about this tricky case more detailed.

2 Answers 2

1

Servlet containers normally use a one-classloader-per-webapp strategy to avoid this hell. So if you have two applications deployed on the same container, the will have different classloaders which satisfy their class resolution and loading needs. Tomcat has a document for this.

Of course, there are some gotchas like working with JDBC drivers (which are one per JVM process) and JNI (a given library can't be loaded more than once by a given JVM or something along those lines) but the general working remains the same.

Sign up to request clarification or add additional context in comments.

4 Comments

Hm. Thanks. So there is no problem to use same classes in different ears/wars. Thanks.
Yes, it shouldn't be a problem. Again, trying out things yourself would be much better. :-)
Ok. What will be in those (JDBC, JNI) cases? Loads first time from random ear/war and after that just retrieve from cache?
The way JDBC drivers work is by registering themselves with the "DriverManager" class. Since the DriverManager is a core class, it is loaded once by the JVM and is shared across the different deployed applications. Hence only one driver can be registered at any given time. Regarding JNI, I think there was a clause in the JNI specification which said loading a single library more than once results in an exception though I can't locate it right now.
0

You have to use packages. com.foo.Test is different from com.foo2.Test.

1 Comment

I know, but if I have some external libs, that I can not manage, what is the loading order for described situation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.