Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

import

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have these is separate files
//SClass.java
package xyz;
public class SClass{
}

// PClass.java

package abc;
public class PClass {
}
they are in the same bin directory
SClass compiles ok but when i compile the PClass it gives the error of import package not found
tell me how to import a package
i do not have classpath set ; is it compulsory for this
what should i set this to
i have tried by putting the class file in the classes folder
of jdk but this still does not work
tell me what to do
Thanks
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A package hierarchy is often (that's not mandatory but strongly advised by JLS) represented by the same directory hierarchy.
If your working directory is, say, javawork, then the file SClass.java should be in javawork/xyz and PClass.java in javawork/abc

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shahid,
If you are using JDK 1.3 you do not need to set a classpath.
Java equates package names with your directory structure. When you are compiling your .java files must be in a directory that matches their package name.
For the examples you've given, the directory structure should be:

When you compile, make sure you are in 'someDir' and enter

If your PClass uses an SClass object, you'll need to add the import statement <code>import xyz.*;</code> to your PClass.java file before you compile PClass.
Hope that helps.

------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
MrShahid khan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic