Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classpath, JARs and Cygwin

 
G C Bhatnagar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I am currently studying for the SCWCD 1.4 exam using the Head First book on Servlets and JSPs. I'm in the 3rd chapter where you develop and depoly a small MVC webapp (about beer).

I've got the J2SE 5 SDK update 4 and Tomcat 5.5.
Here's what I entered into my Cygwin bash shell on Windows XP (adapted from pg. 85 in the HF book):


Here's the top two errors I got:


What I figured was going on in the javac command was this: look in the normal place where you'd find classes (i.e. J2SE 5.0 API) and also look in the specified location (the Tomcat JAR). I guess neither of those locations have javax.servlet.

I checked the J2SE 5.0 API docs and javax.servlet isn't there. I'm not exactly sure how to see what's inside tomcat's JAR file.

I checked the J2EE 1.4 API docs and saw that it does have javax.servlet. So, I downloaded the Sun Java System Application Server Platform Edition 8.1 2005Q2 UR2 which includes the J2EE 1.4 API.

I opened a new shell after installing the J2EE stuff and it gave the same problem. Where is javax.servlet? Where does javac look without any classpath arguments? How do I change that? How do I find what packages are contained in which JAR files?

Is something the matter because I'm using Cygwin? I haven't been able to set any environment variables in Cygwin using the set command. Here's what I typed in:


This didn't create (or modify once created through Windows XP) the CLASSPATH variable. The set manpage is pretty complicated - did I do it correctly?

Should I just use the cmd prompt in Windows?

Answers to any of my 37 questions would be greatly appreciated.

Thanks very much.

Bye bye,
Gaurav Bhatnagar
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The problem is that javac.exe, being a Windows program, thinks CLASSPATH entries should be separated by ';' (semicolon) characters, which, to the bash shell, are statement terminators. You're using colons, which would be correct on UNIX, but not for javac.exe. The bogus classpath keeps javac from finding servlet-api.jar .

So you have two options: one is to use semicolons, carefully escaping or quoting them:

javac -classpath "/cygdrive/c/tomcat5.5/common/lib/servlet-api.jar:classes:." -d classes src/com/example/web/BeerSelect.java

or use the open-source Jikes java compiler, which is available for cygwin (I think it might even be installable by cygwin setup). The cygwin port of Jikes uses colons for CLASSPATH just as any UNIX program would.
 
G C Bhatnagar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much! Your advice was right on. I changed the classpath argument to one in Windows format and the class compiled just fine.

With some experimenting of my own, I've figured out how to get a class listing of what classes are in a JAR file and saw that javax.servlet and so on are actually in the tomcat JAR file.

Thanks again,
Gaurav Bhatnagar
 
Hemal Pandya
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Hi,

Welcome to JavaRanch!
[snip]
So you have two options: one is to use semicolons, carefully escaping or quoting them:

javac -classpath "/cygdrive/c/tomcat5.5/common/lib/servlet-api.jar:classes:." -d classes src/com/example/web/BeerSelect.java

Did you mean to show the escaped version? That would be:

javac -classpath "c:/tomcat5.5/common/lib/servlet-api.jar;classes;." -d classes src/com/example/web/BeerSelect.java

Note also that /cygdrive/c is how cygwin identifies the windows directory c:/. But the front slashes are fine.


or use the open-source Jikes java compiler, which is available for cygwin (I think it might even be installable by cygwin setup). The cygwin port of Jikes uses colons for CLASSPATH just as any UNIX program would.


Wow. I didn't know jikes has a cygwin port. I can't find binaries anywhere, certainly not in cygwin distribution, but the jikes home says it can be compiled under cygwin.

Do you know if it supports the current java spec?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic