• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get this package?

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I was making two different classes like this:
public class dbconn
{
package db.dbconnect;
//**** and rest of codes here

another is:
public class testData
{
package test.data;
import db.dbconnect.*;
//**** and rest of codes here
now both java files are in same directory. I am also setting the classpath for current director by giving following command:
set classpath=.;%classpath%
if i echo the classpath it shows the current directory too. If I try to compile the first one it gets compile easily but now if i try to compile the second one it gives error that package not found.
but strangely if i give packe like:
import db.dbconnect.dbconn;
it accepts. why?
Isn't first style also Ok?
Pl give your comments.
regards,
arun
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all the package statement needs to be the first executable statement of your code.
After you compile the first class, you need to create directory structure that mimics the package path and move the class there.
If your class B is in C:\myprogram folder and you are importing db.dbconnect, there needs to be a dirtectory db in c:\myprogram. The db directory should contain a dbconenct directory which should contain the class you are trying to import.
Hope this helps
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Shivaji for your comments.
But the strange thing is that I am using command javac -d . dbconn.javaThis itself gives that directory structre which ever is needed.(Though I have also confirmed after physically looking at this and it is there) but still the problem remains same.
regards,
Arun
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic