• 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

problem using javac with -classpath option

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
my problem looks prety simple,but dont know why its haunting me.
anyways heres my problem.

There is a folder called "BeerV1" which has "src" and "classes" folders.

i have two files as followes...
under the "src" folder:
1. com.example.model.BeerExpert;
2. com.example.web.BeerSelect;

first i compile the BeerExpert class using -d option, like this

c:\practice\projects\BeerV1>javac -d classes src\com\example\model\BeerExpert.java

... it works just fine, producing the .class file in correct package structure under "classes" folder.

BeerSelect class is a servlet. it has-a BeerExpert. BeerExpert is a "model" class, as in MVC pattern "model". it returns me an arraylist,nothing special. when i compile the BeerSelect the following is the output...

c:\practice\projects\BeerV1>javac -cp "%CATALINA_HOME%\lib\servlet-api.jar" -d c
lasses src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:19: cannot find symbol
symbol : class BeerExpert
location: class BeerSelect
BeerExpert be=new BeerExpert();
^
src\com\example\web\BeerSelect.java:19: cannot find symbol
symbol : class BeerExpert
location: class BeerSelect
BeerExpert be=new BeerExpert();
^
2 errors

then i think, ok, its not able to locate the BeerExpert class, so let me specify classes folder in -classpath option and i do this

c:\practice\projects\BeerV1>javac -cp "%CATALINA_HOME%\lib\servlet-api.jar":clas
ses -d classes src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:4: package javax.servlet does not exist
import javax.servlet.*;
^
src\com\example\web\BeerSelect.java:5: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src\com\example\web\BeerSelect.java:10: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet{
^
src\com\example\web\BeerSelect.java:11: cannot find symbol
symbol : class HttpServletRequest
location: class BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse
^
src\com\example\web\BeerSelect.java:11: cannot find symbol
symbol : class HttpServletResponse
location: class BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse
^
src\com\example\web\BeerSelect.java:19: cannot find symbol
symbol : class BeerExpert
location: class BeerSelect
BeerExpert be=new BeerExpert();
^
src\com\example\web\BeerSelect.java:19: cannot find symbol
symbol : class BeerExpert
location: class BeerSelect
BeerExpert be=new BeerExpert();
^
7 errors

c:\practice\projects\BeerV1>

--------------
so now it cannot import any of the servlet classes as well. WHAT AM I DOING WRONG???
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Classpaths for compiling servlets can get pretty complicated - and will get worse as you add more libraries.

Thats why I use the ANT utility and define classpaths in build.xml. Yes ANT has a steep learning curve but you will be glad you put in the effort.

Bill
 
Anil Chatty
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestion, but technicaly, what did i do wrong in the way i called javac ??
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"%CATALINA_HOME%\lib\servlet-api.jar":classes


I haven't used Windows in a long time, but I think there are two issues here. One is that you can't enclose just part of a classpath in double quotes, it has to be the full path, like

"%CATALINA_HOME%\lib\servlet-api.jar:classes"

The other is that the colon separates classpath entries on Unix operating systems only; Windows uses the semi-colon, so try

"%CATALINA_HOME%\lib\servlet-api.jar;classes"

You can omit the double quotes, since there is no space character in the path.
 
Anil Chatty
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YOU RULE ! ! !

the problem was the ":" colen. i replaces it with semicolen and it worked!

Thanks a ton.
 
reply
    Bookmark Topic Watch Topic
  • New Topic