• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Packages

 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a resonable knowledge of actually programming Java, but I cannot grasp how to get packages working. I understand how to declare that something is part of a package in the code, and that the package hierarchy is produced using directory structure on the hard-drive - but I have no idea where to put this directory structure, and how to make my Java programmes find the package!? E.g if I store a package in d:\MyPackages\PackageOne, how does the compiler find it?
thanks,
Ben
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should compile the files in the package from the directory where the package is stored. To compile Packages on my (linux)pc i would use
peter@linux:~ >javac MyPackages/PackageOne/Class1.java
where "peter@linux:~ >" is the prompt. I also run my applications from the same prompt. I'm not totally sure that windows follows the same rules but it should be similar.
HTH
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
It looks like you want to learn a bit about the options available when using javac:
javac - Java programming language compiler
and
Setting the class path
Good Luck.
 
Dirk Schreckmann
Sheriff
Posts: 7023
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Wood:
but I have no idea where to put this directory structure,

Anywhere you'd like that you can tell the compiler and the JRE (JVM) to find the files.
and how to make my Java programmes find the package!?

with your import statement(s)
E.g if I store a package in d:\MyPackages\PackageOne, how does the compiler find it?

You'll usually let the compiler know the location of relevant packages and classes with the import statements in the class definition. In one of the above links you'll also find information on setting the classpath for the compiler.
The JRE (JVM) will need to also be able to find the necessary classes and packages, in which case you might need to set the classpath accordingly. Some information on doing this is referenced above, and a quick search on this forum is sure to turn up more information. (Note: the search page link is at the top right of this page.)
Good Luck.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic