File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Can't import user-defined packages on Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can Watch "Can New topic

Can't import user-defined packages on Windows

Paulo DeLimma

Joined: Jul 02, 2011
Posts: 9

Hello guys,

I'm a Java beginner trying to follow the chapter order of Bruce Eckel's Thinking in Java, 3rd edition. I downloaded the source code of his "toy examples" and I'm looking forward to solve the exercises, tweak the code and write my own stuff, compiling in the command line with javac. I installed the JDK 6 and ant, compiled the book source code, but still I can't import the package com.bruceeckel.simpletest. When I try to compile code which imports it, it says the package doesn't exist.

I'm using Windows XP, and the user variable PATH is set as:

C:\Sun\SDK\bin;C:\Sun\SDK\jdk\bin;C:\Java\TIJ\Code;C:\Program Files\WinAnt\bin

C:\Sun\SDK\bin => this was set by default by the JDK installation

C:\Sun\SDK\jdk\bin => I did it because javac wasn't being recognized, and it worked.

C:\Java\TIJ\Code => I set it manually, it's the path to the com folder, which contains the book packages.

C:\Program Files\WinAnt\bin => automatically set by the WinAnt installation.

I can't figure out what's the problem, could anyone help?

Thanks in advance.

[Thumbnail for Directories.png]

Paulo DeLimma

Joined: Jul 02, 2011
Posts: 9

I am at an internet cafe and logging out, if someone replies, sorry if I take too long to reply back!
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45277
Welcome to the Ranch

That doesn't sound like a PATH problem. By the way, what do you get when you execute the following instructions at the command line?
javac -version
java -version
Sounds like a problem with the CLASSPATH. don't set a system CLASSPATH. Instead add the location of the Bruce Eckel files. We have an FAQ, and there are details of the -cp tag "java" tool and the "javac" tool in those links. Try something like this when you open a new command lineRemember the .

Other people will probably give better advice how to do it.
Paulo DeLimma

Joined: Jul 02, 2011
Posts: 9

Thank you sir.

The output to the commands you suggested is in the attached image. Everything ok, it seems to me?

Setting the CLASSPATH as you described was just what I needed, so thank you again. I removed the location of the Bruce Eckel files from PATH.

So I have to set the CLASSPATH every time I open the command line, correct?

[Thumbnail for versionOutput.png]

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15036

Or you can specify it when you compile and run the code, using the -cp or -classpath option, for example:

javac -cp .;C\MyFiles\BruceEckel

java -cp .;C\MyFiles\BruceEckel MyProgram

You could put this in a batch file (a file with the *.bat extension) that you can run from the command prompt if you don't want to type the whole command every time.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Paulo DeLimma

Joined: Jul 02, 2011
Posts: 9

Thank you Jesper, I guess I'll use -cp for now.
I agree. Here's the link:
subject: Can't import user-defined packages on Windows
It's not a secret anymore!