• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Help!!! I know packages cant be this difficult. :-(

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to understand packages but its getting a bit difficult.



...compiles fine



Why is my second class giving me this compile error?
package com.example.test does not exist
[ February 23, 2005: Message edited by: Crusty Magmanum ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Crusty, can you change your displayed name to conform to the JavaRanch
naming policy. In short, your name must be a first name and last name, separated by a space and not obviously fake. You can do that here.
Now, about packages. Unless you tell the compiler differently, it will write the class file it generates into the current working directory. Packages work like the file system, so if you have a package named com.example.test, the compiler will expect to find classes in that package in a directory named com/example/test under the current one (or in the classpath, but that's another story). To have the compiler do this automatically, compiler with the -d flag and specify a directory ("." for the current directory is fine). Consult the Java Tutorial chapter on Packages for more info.
[ February 23, 2005: Message edited by: Joe Ess ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might also refer to the chapter on packages in Bruce Eckel's Thinking in Java...
http://www.faqs.org/docs/think_java/TIJ307.htm
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect that the issue is with your directory structure in the file system. Packages correspond to directory names, so for the example you gave, you should have the following structure:

You can compile all of your classes from C:\java:

If MyClass.java is not compiled or has been modified, javac should detect this and compile it before it compiles MyClass2.java.

If this doesn't help fix your problem, please describe the directory structure you are using. Hopefully it will help us think of other things you can try.

Keep Coding!

Layne
[ February 23, 2005: Message edited by: Layne Lund ]
 
C. Magmanum
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much for ur suggestions but I'm still not getting anything positive. This is my commandline input

c:\>javac -classpath /somefile/foo.jar -d classes MyClass2.java

The structure is how u suggested but I am not sure how -classpath (in the commmand-line) affects the import in MyClass.java



...my mum calls me crusty
 
Yup, yup, yup. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic