• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

classpath problems compiling on Windows 2000

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working through the Heads Up JSPs and Servlets book. I've created a directory structure that looks like this:

I have a class called "BeerExpert.class" located in classes\com\example\model. The first line in the source code is:

"package com.example.model;"

I have a java source file called "BeerSelect.java" located in src\com\example\web.

The relevant import statement is:

"import com.example.model.*;"

I open a command window and change to "c:\MyProjects\BeerV1".

I then attempt to compile BeerSelect.java with this command line:
"javac -d classes src\com\example\web\BeerSelect.java"


and get this error message:

"Package com.example.model does not exist"

Can anyone advise me on what I should be doing differently? I'm sure it must be a problem with paths, but I'm stumped.

Thanks.


EDIT by mw: Added Code Tags to keep indentation of directory structure intact. (Otherwise, it's left-justified.)
[ March 19, 2006: Message edited by: marc weber ]
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to tell the compiler where to find the BeerExpert.class file. But keep in mind it will be looking for the directory that contains com.example.model.BeerExpert.class, not just BeerExpert.class. So you need to tell it to look in the classes directory, not in the classes\com\example\model directory. So at the command line, add a -classpath option to tell the compiler the directory that contains the com.example.model package (i.e. the classes directory).

C:\MyProjects\BeerV1>javac -classpath classes -d classes src\com\example\web\BeerSelect.java

This of course will only work if any and all dependent classes have already been compiled into the classes directory. As an alternative, if you want the compiler to compile any dependent classes it encounters (and all the source code is in the src folder), set your classpath to src, and the compiler will compile both the com.example.web.BeerSelect.java file, and the dependent class com.example.model.BeerExpert (i.e. src\com\example\model\BeerExpert.java), along with any other classes either or those two classes are dependent on (as long as the source code is within the classpath specified, just the src directory in this case).

C:\MyProjects\BeerV1>javac -classpath src -d classes src\com\example\web\BeerSelect.java

Give that a try. Delete all the subdirectories in classes, and run the above compile command. You will see both BeerSelect.class and BeerExpert class appear in their appropriate packages within the classes directory.

As an FYI, in more recent versions of Java, the -cp option is an abbreviation (or alias) for the -classpath option. If memory serves me correct, it was added in version 1.4.2.

I hope that helps.
[ March 19, 2006: Message edited by: Mark Vedder ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic