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

classpath issue

Soumil Shah
Ranch Hand

Joined: Jul 13, 2009
Posts: 54
Hi, i am new to the Servlets. My query is regarding classpath. I am trying to run the simple servlet program, but while compiling it is trowing error " cannot find symbol - import java.servlet.*"

Details are --
Apache tomcat is at D:\apache-tomcat-4.1.40-LE-jdk14
JDK is at D:\jdk1.4

Environment variables --
PATH - D:\jdk1.4\bin (for javac and java)
JAVA_HOME - D:\jdk1.4 (java base directory)
CATALINA_HOME - D:\apache-tomcat-4.1.40-LE-jdk14 (tomcat base directory)

And finally...
CLASSPATH - D:\apache-tomcat-4.1.40-LE-jdk14\common\lib\servlet.jar

What else i am missing in the classpath??

Note: I have tested tomcat (through basic HTML and JSP files) and its working fine.

Please help me out from this. I know its very basic question but without this i am not able to proceed with servlets.

Thanks in advance.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Why are you working with such outdated versions of Java SDK and Tomcat?

Versions 1.6 for the SDK and Tomcat 6 have been standard for quite a while - I suspect all the experts here left Java 1.4 and Tomcat 4 long long ago.

Bill
Soumil Shah
Ranch Hand

Joined: Jul 13, 2009
Posts: 54
Ok.. I will install 1.6 .. but my query was related to the classpath.. no probs.. i will first install 6 and try it again.. Thank you for reply ...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Is the problem during compilation? Just make sure that Tomcat's jar files are part of the compilation classpath. It has nothing to do with Tomcat's run-time classpath which is completely different.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hi,
You should be setting the classpath using from the command prompt where you are compiling the servlet.
From your post , I am not sure I correctly understood how you are trying to set the classpath.


Regards,
Amit
Manojkr Jadhav
Greenhorn

Joined: Sep 05, 2009
Posts: 7
you can import

import java.servlet.HttpServletRequest;
import java.servlet.HttpServletResponse;
Soumil Shah
Ranch Hand

Joined: Jul 13, 2009
Posts: 54
amit punekar wrote:Hi,
You should be setting the classpath using from the command prompt where you are compiling the servlet.
From your post , I am not sure I correctly understood how you are trying to set the classpath.



Hi, thanks for reply.

I am setting the CLASSPATH environment variable through Control Panel-> System->Advanced tab->Environment variables.

And i am compiling very basic HelloWorld servlet code ---

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head><title>Hello World</title></title>");
pw.println("<body>");
pw.println("<h1>Hello World</h1>");
pw.println("</body></html>");
}
}

The java compiler is not able to find any of the Servlet related package/class/functions.

Even i have also tried with below classpath setting --- ["." for current directory and D:\TestApache for Development directory]
CLASSPATH = .;D:\TestApache;D:\apache-tomcat-4.1.40-LE-jdk14\common\lib\servlet.jar
Anuj Prashar
Ranch Hand

Joined: Apr 15, 2008
Posts: 99

I guess that you are not using any ide and compiling the code using javac on command line.After making changes to classpath and other variable you need to restart command line for changes to be available to you.Hope this helps.


SCJP 5,SCWCD 5, RHCT
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
It is easy to make syntax errors in environment variables such that Java can't look at the path. Perhaps you should show us exactly what your CLASSPATH ends up looking like.

Open a command prompt window and use the SET command bare to see the environment variables.

Bill
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hi,
If you are setting the CLASSPATH using control panel way then you have to use a new DOS window to compile your code.
The existing DOS window will not reflect the new CLASSPATH changes you did using Control Panel.

Soumil Shah
Ranch Hand

Joined: Jul 13, 2009
Posts: 54
Hi Guys,

Thanks for replies....

I resolved this issue by setting the CLASSPATH through the command prompt at the location where I was compiling my servlet code.

I am not sure what was the problem when I have set the CLASSPATH using control panel. The both classpath value ( through control panel and through command prompt) were same.
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hi,
You may not have opened the new DOS window to compile your code after setting the classpath from Control Panel.
I mentioned that in earlier post.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

I'm moving this to the Beginning Java forum as it really has nothing to do with Servlets, and just learning how to compile Java classes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath issue