*
The moose likes Beginning Java and the fly likes problem using javac  with -classpath option Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem using javac  with -classpath option" Watch "problem using javac  with -classpath option" New topic
Author

problem using javac with -classpath option

Anil Chatty
Greenhorn

Joined: Jun 12, 2007
Posts: 21
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???


SCJP 5.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
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

Joined: Jun 12, 2007
Posts: 21
Thanks for the suggestion, but technicaly, what did i do wrong in the way i called javac ??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
"%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.


Ping & DNS - my free Android networking tools app
Anil Chatty
Greenhorn

Joined: Jun 12, 2007
Posts: 21
YOU RULE ! ! !

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

Thanks a ton.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem using javac with -classpath option
 
Similar Threads
Not able to import
weird problem
Problem in compiling this code
can't import own model
Compilation Problem in CHAP3 example