aspose file tools*
The moose likes Beginning Java and the fly likes Problem in setting CLASSPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in setting CLASSPATH" Watch "Problem in setting CLASSPATH" New topic
Author

Problem in setting CLASSPATH

Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
I have set an environmental variable CLASSPATH which has the value .;C:\Java\jdk5.0\lib\dt.jar;C:\Java\jdk5.0\lib\tools.jar;C:\Java\jdk5.0\lib\servlet-api.jar;C:\Java\jdk5.0\lib\jsp-api.jar

Now I am trying to compile a servlet like:

> javac -classpath E:\ABC\classes XYZServlet.java

In this case I am getting error that package javax.servlet.* not found

And if I do not spcify the -classpath option then I got error:
package com.exampe.model not found

where my servlet has the foolowing line:
import com.example.model.*;

Thus, only one classpath is read.
How to use both the packages?


Hakuna Matata!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Don't worry, the command line does not override your CLASSPATH setting. What is under E:\ABC\classes ? Your java files ? With your command line, I expect to see something like E:\ABC\classes\com\example\model. Are your source files there ?

Another thing, is this a typo ? "package com.exampe.model not found". The "l" in example is missing.


[My Blog]
All roads lead to JavaRanch
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
That was a typing mistake only(in this post)...

If command line does not override the CLASSPATH setting, then why it is the case that I am getting "package javax.servlet not found" when I am specifying -classpath option in the command line and I am getting "package com.example.model not found" instead of "package javax.servlet not found" when I am not specifying the -classpath option.

I have put my .java(helper classes, not servlets) files in E:\ABC\src\com\example\model and my .class files for these .java files are in E:\ABC\classes\com\example\model
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Oops, apologizes. It will override your environment variable. You'll have to use one or the other. Look at this FAQ, and set the current directory "." in the CLASSPATH too. Then compile from the root of your source directory.
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Thanks for the reply, Christophe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in setting CLASSPATH