Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Any import statements are added by the compiler to the final class file

807589Jul 3 2008 — edited Jul 6 2008
Hi,
I have compiled my code against an older version of xerces jar which has reference to some of the framework package classes. But I have tried to run the code with newer version of xcerses package now I am getting class not found exception as framework package is not there in the later version. I have not made any refernce to these classes in the source code. I understand that both needs to be same version. But My question here is the compiled class file when I decompile, it shows that few of the imports that are not actually present in the source code are there, Does the compiler add them for any reason?.

Here is the example code before and after compilation

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.InputSource;
import java.io.*;
import java.util.*;

class Test {
public static void main (String args []){
try {
DOMParser dom = new DOMParser ();
dom.setFeature("http://xml.org/sax/features/validation", true);
dom.parse(new InputSource(new StringReader("/disk5b/vikaskn/server/data/sc/preprocess/SR/SRntNetwork.sc")));
dom.getDocument();
}
catch (Exception e){}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

After compilation I ran the code with old xerces.jar set in my CLASSPATH it works fine.

Then I ran the same compiled code with the new xerces.jar set in my CLASSPATH.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/framework/XMLParser

Then I u used jad utility (which converts class to java file) and got .java file of the class file. It looks as shown below

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.io.StringReader;

// added line ..................



import org.apache.xerces.framework.XMLParser;




// end

import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.InputSource;

class Test
{

Test()
{
}

public static void main(String args[])
{
try
{
DOMParser domparser = new DOMParser();
domparser.setFeature("http://xml.org/sax/features/validation", true);
domparser.parse(new InputSource(new StringReader("/disk5b/vikaskn/server/data/sc/preprocess/SR/SRntNetwork.sc")));
domparser.getDocument();
}
catch(Exception exception) { }
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



Thanks in advance for the help...........
Karani

Edited by: karani on Jul 3, 2008 2:14 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 3 2008
Added on Jul 3 2008
5 comments
245 views