• Post Reply Bookmark Topic Watch Topic
  • New Topic

java class paths  RSS feed

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im trying to extend my program and im having trouble figuring out how to do clas paths correctly. im trying to import a image from a package that is outside of the package inwhich the class is held in. how does a package look? is it just like a folder? how can i tell the class path that im starting at the beginning of the dirs?

incase im not using the word 'class path' correctly im talking about like
"/folder/folder/file.png"

any help would be appreciated, thanks.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ask your ClassLoader to give you resources in your classpath.

Start with the outer package name and separate every package in the path with "/".



Your confusion maybe related to the fact that the current execution directory is not necesarily the same of that where you compiled classes and resources reside.

You could run your application like this:

C:\> java -jar d:\Software\MyApps\app.jar

Hence, you would actually be located on C:\ when you run it, altough your files are in d:\Software\MyApps\app.jar.

If you are using an IDE, like Eclipse or NetBeans you could set up the running environment, so that the currect directory is the same as that of your build path.

I prefer to count on the ClassLoader to get items from the classpath. If what you want is to get an item from the current direcory, just name it.

FileInputStream input = new FileInputStream("currentPath.txt");

I hope this helps!
 
Evan Pierce
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well what i did was i duplicated a class i had in a diffrent package and made a new package in my program and put the duplicated class in it. now i want to redirect the images that i have set inside of that duplicated class to images inside of the new package but when i call bsIO.getURL("M3.png") it goes and accesses my original package and not the package that the duplicated class is in. is there a way to get it to recognize what package its in? at top of the class i have the package set correctly.
oh and im using eclipse.
[ June 13, 2006: Message edited by: Evan Pierce ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!