Two Laptop Bag*
The moose likes Java in General and the fly likes Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Packages" Watch "Packages" New topic
Author

Packages

Amna Arif
Greenhorn

Joined: Jun 21, 2003
Posts: 8
how to create packages in java? I have a problem in setting CLASSPATH variable and I also have problem in compiling programs in a package.
peter greaves
Ranch Hand

Joined: Sep 27, 2002
Posts: 51
packages are created (logically)as they are declared, using the "package" keyword. the JLS governs that. the compiler will create a directory structure that "reflects" your package names. maybe you could post the errors you are getting with yr code, so we could help out?
regs
peter


SJCP 1.2
Amna Arif
Greenhorn

Joined: Jun 21, 2003
Posts: 8
hello
whenever i try to compile a class file in a package after setting CLASSPATH i get the following error message
E:\jdk1.4\bin\lab>javac toy.java
'javac' is not recognized as an internal or external command,
operable program or batch file.
E:\jdk1.4\bin>javac toy.java
error: cannot read: toy.java
1 error
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
'javac' is not recognized as an internal or external command,
operable program or batch file.

This is a PATH issue, not a CLASSPATH issue. The CLASSPATH is concerned with locating Java class files. The PATH is concerned with locating executables, like .exe files.
You probably want to adjust your PATH setting to include the location of javac.exe (which is included with your Java 2 SDK installation).


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
E:\jdk1.4\bin>javac toy.java
error: cannot read: toy.java

Where is toy.java located? It must not be in the E:\jdk1.4\bin directory. Is it in the E:\jdk1.4\bin\lab directory? If it is, then try E:\jdk1.4\bin>javac lab\toy.java
Note that the CLASSPATH setting isn't concerned with locating Java source files, it specifies the location of compiled classes.
Amna Arif
Greenhorn

Joined: Jun 21, 2003
Posts: 8
Actually if there is a class file in a package. To execute it from the package iam setting CLASSPATH but it is not working. The lab package is in JDK1.4\bin\lab. Please help.
Gayathri Prasad
Ranch Hand

Joined: Jun 25, 2003
Posts: 116
Hello,
After u set the path for javac compiler and the following is the procedure I used for compiling and accessing my java files in the package.
I have a folder in the F:\Programs\Java\mypack
The CLASSPATH is set to F:\Java\Programs (i.e the classpath has to be set to the parent folder in which the package resides i.e to the F:\Java\Programs because the mypack folder resides in F:\Java\Programs\mypack )
To compile them u need to compile them in the following way.
F:\Programs\Java>javac mypack\*.java
Cheers,
Gaya3
-------------------------------------------------
Beginning is half done
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Packages
 
Similar Threads
IDE for Java
Eclipse 3.0 package explorer
Problem in compilation
How to complile java classes which exist in different Packages
Issues with JDK 1.4??