• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Having Classpath trouble on my new iMac

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tomcat and Eclipse installed and running. I am going through Head First Servlets and JSP, but I can't compile my first servlet. It can't find the servlets-api.jar in tomcat.

I have a directory with my workspace and servlet

/Users/myUserName/Documents/workspace/project1/src/Ch1Servlet.java

Tomcat is installed here

/Library/tomcat/lib/servlet-api.jar

I'm trying to compile through the terminal with this command. My current directory is

/Users/myUserName/Documents/workspace/project1/

javac -classpath /pathToTomcat/lib.servlet-api.jar -d classes src/Ch1Servlet.java

for my pathToTomcat I have tried all sorts of things, such as

/../../../../../Library/tomcat/

No matter what I try I just can't get it to compile.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hentay Duke:
Tomcat is installed here

/Library/tomcat/lib/servlet-api.jar


Have you mucked around with your Tomcat folder structure? Because that's not right. If Tomcat's installation base is at /Library/tomcat, then that jar file should be at:

/Library/tomcat/common/lib/servlet-api.jar

How did you install Tomcat? Did you move things around afterwards?

for my pathToTomcat I have tried all sorts of things, such as

/../../../../../Library/tomcat/

Trying invalid syntax won't get you anywhere. Supply the actual path to the jar file.
[ February 03, 2008: Message edited by: Bear Bibeault ]
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was the directory structure tomcat set up when I installed it. I haven't messed around with it. I have now created the common directory and put the lib folder into it.

I'm not sure what you mean by invalid syntax. I'm compiling from my project1 folder, which is under my user account etc... Tomcat is installed in my HD Library folder not in my users Library folder. So I was trying to back out until I got to my root HD and then go to tomcat from there. Does that make sense? If so is that not how I should be doing it?

Judging from my directories listed in my first post. What should my -classpath statement look like when I compile?

Please bear with me, I'm not real experienced with this.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hentay Duke:
That was the directory structure tomcat set up when I installed it. I haven't messed around with it. I have now created the common directory and put the lib folder into it.

Where did you get Tomcat? What version? And how did you install it? You shouldn't have to change anything, and doing so is unlikely to help. In fact, it'll probably just boof things up.

I'm not sure what you mean by invalid syntax.

/../../../../../Library/tomcat/
is not a valid path.

We need to get your Tomcat install fixed up before going any further. Please answer my questions above.

Please bear with me, I'm not real experienced with this.


No problem. Let's get your Tomcat install fixed up.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Tomcat 6.0.14, downloaded from one of the mirror sites on Apache. I followed the instructions and got it installed and working no problem. I can start and stop it and view the default tomcat page on my localhost.

I downloaded Eclipse Jee version and when I create a servlet it doesn't have a problem using HttpServletRequest and HttpServletResponse. But when I try to compile from Terminal I get an error because it doesn't recognize the request and response classes.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I stand corrected. Apparently with Tomcat 6 (I still use 5) they got rid of the common folder. Put things back the way they were.

Then show the exact command line that you use when trying to compile. Use the direct path to the jar file (no .. stuff).
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got rid of the common folder, and put things back where they were.

Here's the command I running from my project1 directory.

javac -classpath /Library/tomcat/lib/servlet-api.jar -d classes src/Ch1Servlet.java

I tried adding classpath using setenv in .bash_profile.

If I run env in the terminal it shows a listing

CLASSPATH=.:/Library/Java/home:/Library/tomcat/lib/servlet-api.jar

looks like the classpath includes the servlet-api.jar. But seems like javac can't find it when I compile from terminal.

Is this the way I should be doing it? Pointing to the servlet-api.jar included with tomcat, or is there a better way?
[ February 03, 2008: Message edited by: Hentay Duke ]
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

javac -classpath /Library/tomcat/lib/servlet-api.jar -d classes src/Ch1Servlet.java

If the command line:

ls /Library/tomcat/lib/servlet-api.jar

shows you the jar file, then that should work. If not, please show the error that you are getting.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does show the jar file. Even when I run /Library/tomcat/lib/ and it shows the jars listed servlet-api.jar shops up.

Any other ideas?
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
If not, please show the error that you are getting.

 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't show any errors
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then what problem are we trying to solve?
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I misunderstood. I was getting a can't find symbol error when trying to compile. I thought you were referring to errors when I looked for the class with the env command.

Regardless I finally got it working last night. It was actually a stupid problem, one which was happening because Eclipse was not behaving the way I anticipated. It's actually kind of embarassing.

When creating a Java Project, the organize imports command was unable to find my servlet-api.jar. And I would get the common red underline on the offending classes. So I created a J2EE project and used the organize imports command. I didn't get the red underline and assumed all was well. Well because I wasn't getting any errors in Eclipse I assumed my imports were all taken care of, and never bothered to expand the import section. A stupid rookie mistake, I didn't actually have the servlet package imported. I didn't suspect that since Eclipse didn't complain in J2ee mode the way it did in java mode.

Bottom line is I got my problem fixed. Now I just need to work on why Eclipse doesn't behave the way I thought it should.

I'm sorry if I wasted your time, but thank you for your help and patience anyway.
 
Do not threaten THIS beaver! Not even with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic