[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

working with packages

i have already created a package with the following line of code:

javac -d "d\folder1" MyClass1.java

the file has the package declaration statement 'package p1;' .it runs fine and it creates a package folder in d:\folder1.
Similarly i created 2 other classes(myClass2 and myClass3) in different files as all classes were public  and put them in the same package folder
 but the problem is when i try to access these classes from another file using  'import p1.*;' ,i get an error while if i write 'import p1.myClass1;' or myClass2/myClass3 the programn runs fine.i have already set the classpath varible to the package foler still the problem peersists. Why can't i use "p1.*" ?
0
uniqueaby
Asked:
uniqueaby
1 Solution
 
eicheledCommented:
All of the source files in d:\folder1 should contain the line :

package p1;

(and of course, they should compile :) )

assuming that the resulting .class files are located in the same place (d:\folder1)
then if your CLASSPATH contains 'd:\folder1', all should be well.

Your other class should be able to access all the classes in the package with

import p1.*;

If you are still having trouble, post some code please.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> i have already set the classpath varible to the package foler

Have you set it to d:\folder1\p1 by any chance? You should set it to the parent-directory of the package-folder.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now