Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLClassLoader problem

 
tracey ruark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a class file there?
 
tracey ruark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And where is file ClassToBeLoaded.class located?
 
tracey ruark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic