• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet compile from command line using javac fails  RSS feed

 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
file c:\java\BeeServlet.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



Thanks for any help.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets are also case-sensitive as plain old Java classes are. So "IMPORT" is not same as "import".
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
margaret gillon wrote:
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 )
jdk C:\Program Files\Java\jdk1.6.0_38\bin ( in computer classpath )

There is no such thing as computer classpath or windows classpath. It is just path.
Classpath is exclusive to the compiler where is looks for referenced classes.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
margaret gillon wrote:
I have been working with servlets for serveral months but always using IDE s Eclipse and Netbeans. Time to break the dependency



I am wondering how this code ever worked -- as these compilation errors would exist even with Eclipse or Netbeans.

Henry
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Beginning Java where compilation issues are best handled.
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as computer classpath or windows classpath. It is just path.
Classpath is exclusive to the compiler where is looks for referenced classes.



from Classpath vs Path


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. )
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, finally did it compile?
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, finally did it compile?


Yes, it compiled as soon as I corrected the case.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!