This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Servlet compile from command line using javac fails

 
Ranch Hand
Posts: 336
7
Tomcat Server Ubuntu Linux
  • 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.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora 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
Firefox Browser Fedora 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.
 
author
Posts: 23879
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
Marshal
Posts: 67430
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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: 336
7
Tomcat Server Ubuntu Linux
  • 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: 336
7
Tomcat Server Ubuntu Linux
  • 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. )
 
Bartender
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, finally did it compile?
 
margaret gillon
Ranch Hand
Posts: 336
7
Tomcat Server Ubuntu Linux
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic