• Post Reply Bookmark Topic Watch Topic
  • New Topic

creating packages in java  RSS feed

 
Ebunoluwa Adedoye
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello fiends being trying to creat packages but was unable to create it pls can any one help.
 
Stuart Goss
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

What have you tried out? What are you seeing that goes wrong?

Stuart
 
Thomas West
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem with packages as well. I know how to use them and declare them but say I am using a utility package I have made called com.mine.someutility. If I am working out of the directory c:\java\work then the directory structure has to be c:\java\work\com\mine\someutility.

I was wondering if there is a way so I can keep it in say c:\com\mine\someutility and accessed from there instead of having to copy into my current work directory.

Hope that makes sense.
 
Stuart Goss
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

create your classes in e.g. c:\com\mine\someutility.

Add the "package com.mine.someutility;" line at the beginning of the ".java" file. And don't forget to make those classes you want to use public!

Now if you want to use them (like the JSDK API) you use "import com.mine.someutility.*;" in your other ".java" files (which you can save anywhere, e.g. under "C:\tmp".

Now if you want to compile them you use the "-classpath" otption: "javac -classpath c:\ YourNewFile.java".

Your only using "c:\" here because you only need to say where the package is and not where the classes are.

OK?

Stuart
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you're on your way. See if THIS helps.
 
Thomas West
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for the help. I was able to work it out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!