0

I have a very basic doubt. Please help me understand the following lines from this link http://docs.oracle.com/javase/1.5.0/docs/guide/xml/jaxp/JAXP-Compatibility_150.html

"The solution in the JAXP 1.3 reference name is to change the package names of the Apache libraries used in the implementation. That change lets you reference newer Apache libraries in the classpath, so application developers can use them in the same way that would use any other additions to the Java platform"

How to override the internal implementation class of the jre with a class of same name from reference library in the classpath? Note: I'm assuming they only gave wrapper package to change the name of internal package names, so the internal package name should still exist.

Please explain in detail.

Thanks in advance!!! Anand

1 Answers1

0

Previously some org.apache packages where included in JRE jars "as-is", with complete org.apache package names.

This means that, if a class of mine wanted to use, say, Xerces DomUtil, and had an

import org.apache.xerces.util.DOMUtil;

the root classloader would resolve this class to the version of Xerces in the JRE.

If I wanted to use a newer or different version of Xerces, I could not include it in my application classpath, because the classloader system would give precedence to the Xerces packaged in the JRE.

Now this situation has changed. They took the org.apache packages, and changed them to com.sun.org.apache...internal...

So, if I want to directly use the Xerces packaged with the JRE, i can import :

import com.sun.org.apache.xerces.internal.util.DOMUtil;

(Eclipse will give error telling us not to use packages inside com.sun .. but still the class is there and we can change the access restrictions if we want)

This version is used by all the JRE classes, like JAXP.

This let me free to put in my classpath a newer version if Xerces, and use it from my application without interfering with the JRE ones.

They were repackaged by simply renaming the package. This means moving it from, for example, the folder

org/apache/xerces/util

to the folder

com/sun/org/apache/xerces/internal/util

on the hard drive of some JRE guy, and then changing inside .java files the

package org.apache.xerces.util;

to

package com.sun.org.apache.xerces.internal.util;

So, from a JVM point of view, they are totally different classes.

Simone Gianni
  • 11,426
  • 40
  • 49
  • Hi Simone, Thanks for your reply, but if those old packages "org.apache" is still there, how come the classes from class path will be loaded.In JRE, the old packages was removed or was it only renamed( by writing a wrapper class that just inherits the old apache class)? This was my doubt. Please clarify. – user3292957 Sep 06 '14 at 10:10
  • I clarified the answer, please accept it if you think it answer your question. – Simone Gianni Sep 06 '14 at 10:44
  • Hi Simone, Thanks for your clarification. Under JRE 7->xml.jar I could see that the old packages still exist. For example, org.apache.xpath package is still there in jre7. This is why im having trouble understanding this concept. If it still exist how come the new libraries with same name from class path will be loaded? Please have a look into jre jar, so that you can understand and help me better. Thanks for your patience – user3292957 Sep 06 '14 at 11:31
  • I have no xml.jar in my java-7-openjdk-i386, are you sure that jar is coming from JRE? – Simone Gianni Sep 06 '14 at 11:34
  • Yes i saw this in websphere application serverv8.5 jre. – user3292957 Sep 06 '14 at 13:00
  • I just went through this link. https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014233877 ... It says that Sun's jre and ibm jre differs. So one last question, if IBM is not renaming apache libraries for XML processing, how will it handle the original problem of not being able to point to latest apache libraries in classpath? – user3292957 Sep 06 '14 at 13:32
  • Hi Simone, first of all, a very sincere apology for not communicating all the facts(like using IBM jre). And thanks for your efforts to help me understand. – user3292957 Sep 09 '14 at 17:31