Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Imorting packages

 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To import a package that create by me , should it be in the current directory where I run the program
 
Hiruka Sandev
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need not have it in the current directory if you have the path to your package (i.e the package to import) in your classpath.
 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiruka Sandev wrote:You need not have it in the current directory if you have the path to your package (i.e the package to import) in your classpath.


Please Explain how do I do that
 
Hiruka Sandev
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the package you created is at C:\Java\MyPackage and the class you are trying to compile(HelloWorld.java) is in the current directory, you could try

javac -classpath c:\Java HelloWorld.java
java -classpath .;c:\Java HelloWorld
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic