Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes import and package compile errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import and package compile errors" Watch "import and package compile errors" New topic
Author

import and package compile errors

Linda Pan
Ranch Hand

Joined: Sep 24, 2001
Posts: 96
I am trying to compile Bruce Eckel's code in "thinking in Java". I am using Win98 Jdk 1.3. I have a set-up of all my source code in c:\works\java and my classes in c:\works\classes. I did a sample package and import and works fine.

Now trying to compile the following code in "c:\works\java" :


And in "c:\works\java\com\bruceeckel\Simpletest\", there are a bunch of java files.

I enter c:\works\java> javac -d c:\works\classes Leaf.java
I'm getting the following error:


Leaf.java:3: package com.bruceeckel.simpletest does not exist
import com.bruceeckel.simpletest.*;
^
Leaf.java:7: cannot resolve symbol
symbol : class Test
location: class Leaf
static Test monitor = new Test();
^
Leaf.java:7: cannot resolve symbol
symbol : class Test
location: class Leaf
static Test monitor = new Test();
^
3 errors
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
Hi Linda,

The simple problem is that you did not put the code of Bruce Eckel in class path.

Just put the base directory of the compiled clsses in classpath.
e.g if your Test.class and other BruceEkel's clases are in this package
C:\works\java\com\bruceeckel\Simpletest\Test.class

Just add c:\works\java in your classpath and it will start working.

Regards
Sandeep
Daniel Mayer
Ranch Hand

Joined: Sep 09, 2004
Posts: 103
Take a look at the case of the simpletest package. Your import declaration is lowercase, your directory uppercase. For the compiler, they are not the same.
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
Originally posted by Daniel Mayer:
Take a look at the case of the simpletest package. Your import declaration is lowercase, your directory uppercase. For the compiler, they are not the same.


I think there is no case sentivity of folder in windows. Rite?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I think there is no case sentivity of folder in windows. Rite?

The situation here is that Java is case sensitive. If you've access to a Windows machine, a good way to determine an answer to your question is to go ahead and try it. I just did, and the case of the folders must match that of the package names.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
Hi Dirk,

Thanks for your reply.
But i have also tested a small program.
Let me explain what i have tested:



This code is working very fine, when i put the Test1.java in a windows folder "pack1".

Now what i did is, i did not change any directory, just modified the first line of Test1.java from "package pack1 to package PacK1"

Now i tried compiling and runnung Test1, is runing very fine.

Regards
Sandeep Jindal
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
When I try your experiment with Java version 1.5.0-rc and version 1.4.2_05 on Windows XP, it results in NoClassDefFoundError: pack1/Test1 (wrong name: PacK1/Test1) in both cases.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: import and package compile errors
 
Similar Threads
Problems with importing from another source code
about accessing and importing from directory
How do I compile mt Tag Handler...?
compilation failed
compilation failed