Class.forName(String ClassName) throwing ClassNotFoundException

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2006
Posts: 2,415
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 256
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #11
Jun 22nd, 2009
He says he is trying it from outside of the IDE.

@OP, you are obviously contradicting yourself when you say you know the basics of the classpath then talk about moving to the source directory. You also contradict yourself about those points when I ask you for the classpath, and you give me a package path style reference to a source file, then do the same thing when I ask after the full filepath of the actual class (not source file) to be loaded.

Now, provide me with the classpath you use to execute the command (if none, say none), and provide me with the full classname with package (class name not source file name), and provide me with the full filepath to the class to be loaded (full filepath). Also, provide me with the full filepath to the directory in which you find yourself when you execute the command, and provide the full and exact command you used to execute the command, and provide me with the full stacktrace, not your own generated error message.
Last edited by masijade; Jun 22nd, 2009 at 1:55 pm.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 39
Reputation: multicoder is an unknown quantity at this point 
Solved Threads: 0
multicoder multicoder is offline Offline
Light Poster

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #12
Jun 23rd, 2009
Originally Posted by masijade View Post
provide me with the classpath you use to execute the command (if none, say none),
I am not providing any classpath to the cmd.this is the command m hitting with cmd -

provide me with the full classname with package (class name not source file name),
C:\Harvester\build\classes\au\com\allhomes\listing\harvester\harness\ListingTestHarnessConfiguration.class

provide me with the full filepath to the class to be loaded (full filepath).
C:\Documents and Settings\pritam\Desktop\au\com\allhomes\listing\harvester\parse\RealEstateCoParserConfiguration.java

provide me with the full filepath to the directory in which you find yourself when you execute the command,
Executing the (above) said command from 'C:\'
and provide the full and exact command you used to execute the command,
java -Xmx512m au.com.allhomes.listing.harvester.harness.ListingTestHarness --inputHtml /Harvester/build/classes/sample/data/rsearch.html --listingType residentialSale --parserConfigImpl au.com.allhomes.listing.harvester.parse.RealEstateCoParserConfiguration --urlConfigFile /Harvester/build/classes/sample/data/local_url_map.properties --outputXml results-realestate.xml --pageType listingPage
And getting the anything from printStackTrace , tried below code -
  1. StringWriter sw = new StringWriter();
  2. PrintWriter pw = new PrintWriter(sw);
  3.  
  4. e.printStackTrace(pw);
  5. e.getStackTrace();
  6. System.out.println("Error = " + sw.toString());
  7. throw new IllegalArgumentException("Failed to load** parserConfigImpl [" + parserConfigurationClassName + "]: Class not found");
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,415
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 256
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #13
Jun 23rd, 2009
Originally Posted by multicoder View Post
I am not providing any classpath to the cmd.this is the command m hitting with cmd -
Okay, so what is the value of the System CLASSPATH environment variable?

C:\Harvester\build\classes\au\com\allhomes\listing\harvester\harness\ListingTestHarnessConfiguration.class
Here I wanted the class name (e.g. au.com.allhomes.listing.harvester.harness.ListingTestHarnessConfiguration)

C:\Documents and Settings\pritam\Desktop\au\com\allhomes\listing\harvester\parse\RealEstateCoParserConfiguration.java
Compiled class filepath not the source file path, I couldn't, to tell you the truth, care less about the source file at this point, but I assume the above (where I wanted the classname) is it, and I will assume the classname I provided is correct.

Executing the (above) said command from 'C:\'
Well, if you are executing directly from C:\, and not from C:\Harvester\build\classes\ (assuming '.' is in the System CLASSPATH), then of course it is ClassNotFound (depending on what the system classpath is). You should actually be getting a ClassNotFound on the "main" class.

java -Xmx512m au.com.allhomes.listing.harvester.harness.ListingTestHarness --inputHtml /Harvester/build/classes/sample/data/rsearch.html --listingType residentialSale --parserConfigImpl au.com.allhomes.listing.harvester.parse.RealEstateCoParserConfiguration --urlConfigFile /Harvester/build/classes/sample/data/local_url_map.properties --outputXml results-realestate.xml --pageType listingPage
And getting the anything from printStackTrace , tried below code -
  1. StringWriter sw = new StringWriter();
  2. PrintWriter pw = new PrintWriter(sw);
  3.  
  4. e.printStackTrace(pw);
  5. e.getStackTrace();
  6. System.out.println("Error = " + sw.toString());
  7. throw new IllegalArgumentException("Failed to load** parserConfigImpl [" + parserConfigurationClassName + "]: Class not found");
why not simply
  1. e.printStackTrace();
  2. throw new IllegalArgumentException("Failed to load** parserConfigImpl [" + parserConfigurationClassName + "]: Class not found");
and let the stacktrace print to STDERR. It's only to get the complete stacktrace, and you can, if you want, remove it later.
Last edited by masijade; Jun 23rd, 2009 at 3:53 am.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 39
Reputation: multicoder is an unknown quantity at this point 
Solved Threads: 0
multicoder multicoder is offline Offline
Light Poster

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #14
Jun 23rd, 2009
Originally Posted by masijade View Post
Okay, so what is the value of the System CLASSPATH environment variable?
C:\Program Files\Java\jdk1.6.0_14\lib;
this is System CLASSPATH environment variable
Here I wanted the class name (e.g. au.com.allhomes.listing.harvester.harness.ListingTestHarnessConfiguration)
Thnx. i got it now, u mean complete class name like u said above

Compiled class filepath not the source file path, I couldn't, to tell you the truth, care less about the source file at this point, but I assume the above (where I wanted the classname) is it, and I will assume the classname I provided is correct.
The complete path to the class files(compiled files and with extension .class)is like
C:\Harvester\build\classes\au\com\allhomes\listing\harvester
Well, if you are executing directly from C:\, and not from C:\Harvester\build\classes\ (assuming '.' is in the System CLASSPATH), then of course it is ClassNotFound (depending on what the system classpath is). You should actually be getting a ClassNotFound on the "main" class.
there I put ';' in the system classpath but what is the significance of '.' in the System CLASSPATH ?
and how the user vairable 'classpath' and the 'CLASSPATH' (its in capital, which i get to see often) from System variables list below it...?Plz explain me this too,even if its the out of scope of the post.

why not simply
  1. e.printStackTrace();
  2. throw new IllegalArgumentException("Failed to load** parserConfigImpl [" + parserConfigurationClassName + "]: Class not found");
and let the stacktrace print to STDERR. It's only to get the complete stacktrace, and you can, if you want, remove it later.
I tried with the same but I am not getting apart from the
Error: Cannot read the urlConfigFile [/Harvester/build/classes/sample/data/local
_url_map.properties]
java ListingTestHarness <options>
Where options include:
    --inputHtml <htmlFile>                  The HTML file to parse.
    --listingType <residentialSale | commercialSale | businessSale | ruralSale |
 residentialRental | commercialRental>
    --parserConfigImpl <parserConfigImpl>   The parser configuration to use.
    --parserClassImpl <parserClassImpl>     [Optional]: The parser class to use.

    --urlConfigFile <urlConfigFile>         A mapping of remote URLs to local te
st resources.
    --pageType <listingPage | searchPage>   The type of HTML page being harvested.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 39
Reputation: multicoder is an unknown quantity at this point 
Solved Threads: 0
multicoder multicoder is offline Offline
Light Poster

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #15
Jun 23rd, 2009
Also I noticed one thing with the netbeans behavour, which is very strange for me.
If I change the code, like the test/string inside

throw new IllegalArgumentException("Failed to load** parserConfigImpl [" + parserConfigurationClassName + "]: Class not found");

Like as u can see i put the ** in the string and compiled the project again.Now if i execute it from the cmd i cant see the change in the output exception i got.
what wrong with my concepts..??
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,415
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 256
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #16
Jun 23rd, 2009
'.' is the "current" directory symbol.

How to get the value of an environment variable is an OS question, but for Windows type "set CLASSPATH" (and it should be uppercase not lowercase).

As far as the error posted above, that is not one that has to do with the problem you say you've been having, and to solve that one does C:\Harvester\build\classes\sample\data\local exist? Is it locked? Do you have permission to it?
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,415
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 256
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #17
Jun 23rd, 2009
Originally Posted by multicoder View Post
Also I noticed one thing with the netbeans behavour, which is very strange for me.
If I change the code, like the test/string inside

throw new IllegalArgumentException("Failed to load** parserConfigImpl [" + parserConfigurationClassName + "]: Class not found");

Like as u can see i put the ** in the string and compiled the project again.Now if i execute it from the cmd i cant see the change in the output exception i got.
what wrong with my concepts..??
And if you are getting the error you posted directly before this post, then look at that error, as it is a completely different error than you have been getting.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 39
Reputation: multicoder is an unknown quantity at this point 
Solved Threads: 0
multicoder multicoder is offline Offline
Light Poster

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #18
Jun 23rd, 2009
Thnx.Yes i had noticed this thing before.I used to get the exception cannot find the file local_url_propeties because i had moved the folder data for some experimenting purpose.
And when i realize this i kept it back.Now I had did it again and resolved with that prev error.
The error I am facing now is this exception I am talking about -
Error: Failed to load parserConfigImpl [au.com.allhomes.listing.harvester.parse.
RealEstateCoParserConfiguration]: Class not found
java ListingTestHarness <options>
Where options include:
--inputHtml <htmlFile> The HTML file to parse.
--listingType <residentialSale | commercialSale | businessSale | ruralSale |
residentialRental | commercialRental>
--parserConfigImpl <parserConfigImpl> The parser configuration to use.
--parserClassImpl <parserClassImpl> [Optional]: The parser class to use.

--urlConfigFile <urlConfigFile> A mapping of remote URLs to local te
st resources.
--pageType <listingPage | searchPage> The type of HTML page being harvested.
au.com.allhomes.listing.harvester.parse.
RealEstateCoParserConfiguration is my implementation of the
interface which I need to pass as a 'parserConfigImpl' parameter to the cmd.
But it throws the exception classNotFound..??
sorry if i confused u between these both errors.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,415
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 256
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #19
Jun 23rd, 2009
Lets try to cut this short. Execute the command as follows:
  1. java -Xmx512m -cp C:\Harvester\build\classes au.com.allhomes.listing.harvester.harness.ListingTestHarness ...
or
  1. cd C:\Harvester\build\classes
  2. java -Xmx512m -cp . au.com.allhomes.listing.harvester.harness.ListingTestHarness ...
Last edited by masijade; Jun 23rd, 2009 at 5:13 am. Reason: And please stop sending me PM's. Keep the conversation here and I'll get to it when I get to it.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 39
Reputation: multicoder is an unknown quantity at this point 
Solved Threads: 0
multicoder multicoder is offline Offline
Light Poster

Re: Class.forName(String ClassName) throwing ClassNotFoundException

 
0
  #20
Jun 23rd, 2009
Originally Posted by masijade View Post
Lets try to cut this short. Execute the command as follows:
  1. java -Xmx512m -cp C:\Harvester\build\classes au.com.allhomes.listing.harvester.harness.ListingTestHarness ...
or
  1. cd C:\Harvester\build\classes
  2. java -Xmx512m -cp . au.com.allhomes.listing.harvester.harness.ListingTestHarness ...
For this I got this -

C:\>java -Xmx512m -cp  au.com.allhomes.listing.harvester.harness.ListingTestHarn
ess --inputHtml /Harvester/build/classes/sample/data/rsearch.html --listingType
residentialSale --parserConfigImpl au.com.allhomes.listing.harvester.parse.RealE
stateCoParserConfiguration --urlConfigFile /Harvester/build/classes/sample/data/
local_url_map.properties --outputXml results-realestate.xml --pageType listingPa
ge
Unrecognized option: --inputHtml
Could not create the Java virtual machine.


[QUOTE=masijade;897587]
Got this after above -
  1. Exception in thread "main" java.lang.NoClassDefFoundError: au/com/allhomes/listi
  2. ng/harvester/harness/ListingTestHarness
  3. Caused by: java.lang.ClassNotFoundException: au.com.allhomes.listing.harvester.h
  4. arness.ListingTestHarness
  5. at java.net.URLClassLoader$1.run(Unknown Source)
  6. at java.security.AccessController.doPrivileged(Native Method)
  7. at java.net.URLClassLoader.findClass(Unknown Source)
  8. at java.lang.ClassLoader.loadClass(Unknown Source)
  9. at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
  10. at java.lang.ClassLoader.loadClass(Unknown Source)
  11. at java.lang.ClassLoader.loadClassInternal(Unknown Source)
  12. Could not find the main class: au.com.allhomes.listing.harvester.harness.Listing
  13. TestHarness. Program will exit.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC