0

I have one query regarding Weblogic server 11 G class loading infrastructure.

Lets say I have two application jars named A.jar and B.jar loaded in classpath during server start up.

Both jar contains class say LoadMe.class and sever loads LoadMe.class from jar A.jar by default.

Now I want to alter above default behavior and want to load that class from B.jar instead of A.jar.

How can I do that?

Any help will be appreciated.

Ketan
  • 2,612
  • 5
  • 31
  • 44

1 Answers1

0

Whenever you use LoadMe class for the first time the ClassLoader will try to resolve the dependency using the CLASSPATH.

Now if you have to load the class from B.jar, then you will have to explicitly place path to that jar first and A.jar second in the CLASSPATH. So the ClassLoader will pick the class from B.jar first.

Try this link for more on ClassLoaders

Read this and change the classpath and the problem should be solved

Setting classpath in WebLogic 11G

UPDATE:

System.out.println("Classpath dependency for LoadClass: ");
URLClassLoader classLoader = (URLClassLoader)LoadMe.class.getClassLoader();
System.out.println(Arrays.toString(classLoader.getURLs()));

System.out.println("Classpath dependency for Context: ");
URLClassLoader classLoader1 = (URLClassLoader)Thread.currentThread().getContextClassLoader());
System.out.println(Arrays.toString(classLoader.getURLs()));
Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120
  • But is there not any way to instruct class loader to load specific package from specific jar by configfuration ....placing first or seconds seems some patch solution – Ketan Dec 03 '12 at 13:54
  • no it is not. That is the way CLASSPATH and ClassLoaders work in Java. – Narendra Pathai Dec 03 '12 at 13:55
  • @Ketan https://forums.oracle.com/forums/thread.jspa?threadID=1032064 to change the classpath for WebLogic 11G – Narendra Pathai Dec 03 '12 at 14:49
  • I gone through it but still not getting any hint on way to configure order of class loading? Can you help me for this ? – Ketan Dec 04 '12 at 06:47
  • In 11g in case you want to modify the classpath you should be changing the same in **Server Start Tab** in server configuration of admin console. All restarts of the managed servers should be handled by admin console. Essentially it prevents errors. http://docs.oracle.com/cd/E28389_01/apirefs.1111/e13952/pagehelp/Corecoreserverserverconfigserverstarttitle.html – Narendra Pathai Dec 04 '12 at 06:55
  • yes but it did not help me how to configure to achieve my requirement ? – Ketan Dec 05 '12 at 07:37
  • Add **MANIFEST.MF** file in a **META-INF** directory of your ear file, if present skip this step. Then add `Class-Path: lib/B.jar lib/A.jar` in a new line in the MANIFEST.MF file. https://blogs.oracle.com/olaf/entry/jdev_including_a_classpath_in – Narendra Pathai Dec 05 '12 at 08:07
  • @Ketan can you execute above updated code in the class where you are getting this problem? – Narendra Pathai Dec 06 '12 at 13:42