I am trying to compile a servlet from the command line on Windows XP sp3. I have the same problem at home on Windows7 pro. The compile fails, I think because it cannot find the servlet-api.jar? I have added my tomcat libraries to the windows classpath and my java jdk to the class path. I think there is a way to add the location of a specific library to the javac command but haven't had any success so far. When I compile a regular java class with c:\ javac c:\java\ilenam.java the compile works. Tomcat is working and I have localhost and can get to the Tomcat example files.
I have been working with servlets for serveral months but always using IDE s Eclipse and Netbeans. Time to break the dependency
Windows classpath .;c:\program files\java;C:\Program Files\Java\jdk1.6.0_38\bin;C:\Program Files\Java\jdk1.6.0_38\bin\jr.jar;C:\tomcat\lib\
Tomcat directory c:\Tomcat\lib ( in computer classpath )
Project directly c:\java
jdk C:\Program Files\Java\jdk1.6.0_38\bin ( in computer classpath )
Below is my syntax and the output from the compiler. The file is the BeeServlet.java from the Cattledrive page Cattledrive Servlets
Servlets are also case-sensitive as plain old Java classes are. So "IMPORT" is not same as "import".
I was using my editor from another language and it beautified the code. The compile works and uses the classpath so I didn't need to add the tomcat directory.
Shame on me.
I am wondering how this code ever worked -- as these compilation errors would exist even with Eclipse or Netbeans.
No it wouldn't have run. I did not try this code in the IDE as this is a new project and I didn't want the IDE directory structure. I just tried compiling non-servlet classes I had written previously to make sure I had the syntax correct for the javac from the command line.
Difference between PATH and CLASSPATH in Java
Here are some of the common difference between PATH vs CLASSPATH in Java :
1)Main difference between PATH and CLASSPATH is that PATH is an environment variable which is used to locate JDK binaries like "java" or "javac" command used to run java program and compile java source file. On the other hand CLASSPATH environment variable is used by System or Application ClassLoader to locate and load compile Java bytecodes stored in .class file.
2) In order to set PATH in Java you need to include JDK_HOME/bin directory in PATH environment variable while in order to set CLASSPATH in Java you need to include all those directory where you have put either your .class file or JAR file which is required by your Java application.
3) Another significant difference between PATH and CLASSPATH is that PATH can not be overridden by any Java settings but CLASSPATH can be overridden by providing command line option -classpath or -cp to both "java" and "javac" commands or by using Class-Path attribute in Manifest file inside JAR archive.
4) PATH environment variable is used by operating system to find any binary or command typed in shell, this is true for both Windows and Linux environment while CLASSPATH is only used by Java ClassLoaders to load class files.
Windows classpath is a Windows System Environmental variable accessed from the Windows control path by an administrator.
Windows path is a different Windows System Environmental variable , also accessed from the control panel by an administrator and used by many languages not just Java ( see #4. )