Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't import user-defined packages on Windows

 
Paulo DeLimma
Greenhorn
Posts: 9
C++ Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Directories.png
[Thumbnail for Directories.png]
Package Path
 
Paulo DeLimma
Greenhorn
Posts: 9
C++ Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am at an internet cafe and logging out, if someone replies, sorry if I take too long to reply back!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 9
C++ Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
versionOutput.png
[Thumbnail for versionOutput.png]
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15435
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 MyProgram.java

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.
 
Paulo DeLimma
Greenhorn
Posts: 9
C++ Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jesper, I guess I'll use -cp for now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic