File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Package Import Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package Import Problem" Watch "Package Import Problem" New topic
Author

Package Import Problem

jorge Garcia
Greenhorn

Joined: Jan 09, 2008
Posts: 16
This should be basic but I can't get it the compiler to recognize a package I created.

The file is located at c:\program files\java\com\AJF\ReadAFile.class

At top of the class, 'ReadAFile', I put this - package com.AJF;

In the class I'm building, here is the import statement - import com.AJF.*;

Environment Class Path is - ;C:\Program Files\Java\jre1.6.0_03\lib;C:\Program Files\Java\com

Error Using NetBeans says -

Compiling 1 source file to C:\JavaProjects\parse\build\classes
C:\JavaProjects\parse\src\parse\Main.java:4: package com.AJF does not exist
import com.AJF.*;

Any ideas why the compiler can't see the package?

Thanks again for the help.
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
for starters, you don't need to import the classes when you declare your current class inside that package. All classes in AJF are available to all classes in that package. No need to import com.AJF.*;
jorge Garcia
Greenhorn

Joined: Jan 09, 2008
Posts: 16
It's sitting outside the class.
jorge Garcia
Greenhorn

Joined: Jan 09, 2008
Posts: 16
Ok. The answer just tripped in my brain. It's the source file, it has to be in a directory with the hierarchy that matches the package name. It's working now.
jorge Garcia
Greenhorn

Joined: Jan 09, 2008
Posts: 16
Lol,I take that back. It works in Netbeans but not in a test class written in a in textpad. Weird. Compiler can't find the class. I think it is working in Netbeans because I added the folder in maybe. Still can't figure this out.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

"com" shouldn't be part of the CLASSPATH entry; in other words, you want to include

C:\Program Files\Java

not

C:\Program Files\Java\com

The classpath entries denote directories in which the top-level-directories of class hierarchies appear, not those top-level-directories themselves.


[Jess in Action][AskingGoodQuestions]
jorge Garcia
Greenhorn

Joined: Jan 09, 2008
Posts: 16
Ok, I got it to work by compiling & running the file from the command line. What's weird is in NetBeans, and JCreator, I still get the ' package doesn't exist' error at compile time. I looked around around for a solution to this but don't see anything. I have no idea why this would happen.
jorge Garcia
Greenhorn

Joined: Jan 09, 2008
Posts: 16
Figured it out. With netbeans, you have to right click the project get to properties and add the library.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Package Import Problem