File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes URLClassLoader problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "URLClassLoader problem" Watch "URLClassLoader problem" New topic
Author

URLClassLoader problem

tracey ruark
Greenhorn

Joined: Aug 02, 2009
Posts: 4
I've searched the topics in this forum and cam across many people who seem to have the same problem as me, but my problem remains.

I'm simply trying to load a class that isn't in the classpath of my app. No matter what I do or what I try it simply cannot find the class

Here is my code:




And here is the output:




What am I doing wrong?!?!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is there a class file there?
tracey ruark
Greenhorn

Joined: Aug 02, 2009
Posts: 4
David Newton wrote:Is there a class file there?


Yes, I complied the file already to check it.

Here's the contents of the file at E:\URLClassLoaderTesting_TEMP\projects\project1\tests\ClassToBeLoaded.java
(It is just a dummy class for the proof of concept)

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

And where is file ClassToBeLoaded.class located?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
tracey ruark
Greenhorn

Joined: Aug 02, 2009
Posts: 4
Rob Prime wrote:And where is file ClassToBeLoaded.class located?


That is an excellent question. I say that because when I started this whole thing I dropped the .class file right next to the java file. However, when the .java and .class file reside next to each other in the same directory the program spits this out at me:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

In what folder are you when you're executing the JVM? It should be E:\URLClassLoaderTesting_TEMP\projects\project1. Also, you error tells me that the .class file does not think it belongs in the tests package; the fully qualified name in the .class file is ClassToBeLoaded, not tests.ClassToBeLoaded.

Have you perhaps created the .class file before you added the package statement?
tracey ruark
Greenhorn

Joined: Aug 02, 2009
Posts: 4
Rob Prime wrote:In what folder are you when you're executing the JVM? It should be E:\URLClassLoaderTesting_TEMP\projects\project1. Also, you error tells me that the .class file does not think it belongs in the tests package; the fully qualified name in the .class file is ClassToBeLoaded, not tests.ClassToBeLoaded.

Have you perhaps created the .class file before you added the package statement?


Ah Hah! Thank you. It's been so many years since I've worked with java I'd completely forgotten about how it works at it's most fundamental levels.

My new code looks like this:



My output now looks like this, which is what I'm after:



Thank you so much Mr. Prime!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLClassLoader problem