File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classpath issue

 
Soumil Shah
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
amit punekar
Ranch Hand
Posts: 544
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Manojkr Jadhav
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can import

import java.servlet.HttpServletRequest;
import java.servlet.HttpServletResponse;
 
Soumil Shah
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
Android Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 544
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 544
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic