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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

classpath issue while compiling through cmd prompt

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,

I'm new to servlets and I was working on my first servlet program. (using Head First Servlets & JSP book).

When i try to compile it through command prompt I had to give paths to my classfiles. (UserSelect.java references other files from classes\model\...)
But I had to include the path to the jar file also since " -cp " overrides the CLASSPATH set in environment variable (in Win).


javac -d C:\Jspace\Ecafe\classes -cp "C:\Jspace\Ecafe\classes";"C:\From Pen\Tomcat\apache-tomcat-5.5.26\apache-tomcat-5.5.26\common\lib\servlet-api.jar" web\UserSelect.java

Is there a better way to do this? I tried to include "C:\Jspace\Ecafe\classes" in the CLASSPATH environment variable as below

%CLASSPATH%;C:\Jspace\Ecafe\classes;C:\From Pen\Tomcat\apache-tomcat-5.5.26\apache-tomcat-5.5.26\common\lib\servlet-api.jar;

but it doesn't seem to work. Also I would like to know what %CLASSPATH% means?

 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please take a look at this.

Thanks,
Srikkanth
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
On Windows, you must put directory names that contain spaces between quotes:

set CLASSPATH=%CLASSPATH%;C:\Jspace\Ecafe\classes;"C:\From Pen\Tomcat\apache-tomcat-5.5.26\apache-tomcat-5.5.26\common\lib\servlet-api.jar";.

Note that you did this with the "-cp" switch - you must also do it when you set the CLASSPATH environment variable.

%CLASSPATH% is the value of the CLASSPATH variable, so the line above says "Set CLASSPATH to whatever is in the CLASSPATH now plus this additional stuff".

Note the "." as the last entry of the CLASSPATH - "." means "the current directory".

When you're writing larger programs and you want to be able to compile them from the command line easily, it's better to learn and use a build tool such as Ant.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
ok... thanks all. That was quick reply. The problem was with the directory name as rightly pointed out Jesper.
It compiles fine now. :-)
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Jesper,

"." is not mandatory right? I compile my application from C:\JSpace\Ecafe\src\com\example> and my class files are in C:\JSpace\Ecafe\classes so there is no need to add "." i believe.
 
Marshal
Posts: 80140
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Moving to servlets forum. I would recommend you keep the . in your classpath, in case you invoke a file in your current directory.
Only set a classpath with the -cp flag, or (for a lasting change) with the set instruction on the command prompt. Don't set it in "environment variables" unless you can't find files in the current directory.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello everyone,

It was working fine till yesterday but again today while i compile i get " javax.servlet.http not found" error.

Where do i physically find this file. I thought it is available with the src collection inside JDK folder. But I couldn't find it there.

 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I found it within the jar file bundled with Tomcat. Wonder what could be the mistake in classpath as I had given exactly as above and it worked yesterday.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Have you included classpath in Window's Environment variable or only at command prompt while compiling?
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
at command line using the cmd set CLASSPATH.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi..

I am also getting the same issue..did you get a fix for this? If yes can you please share it here..

Regards,
Disha
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Yes it got fixed. Are you still facing any issues.
 
Dhanashri Tilekar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello,

Thanks for your reply

I am getting the following error..

C:\Program Files\Apache-Tomcat-7\apache-tomcat-7.0.53\webapps\DEMO\WEB-INF\class
es>javac DemoServlet.java
javac: file not found: DemoServlet.java
Usage: javac <options> <source files>
use -help for a list of possible options

I have set the CLASSPATH VARIABLE, PATH VARIABLE, JAVA_HOME VARIABLE....All these Environmental variables I have set in system settings-Advanced settings.

I am not getting what is going wrong here..I am new to servlets

Thanks and Regards,
Disha
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not post the same question multiple times. Let's continue the discussion in this duplicate thread.
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
    Bookmark Topic Watch Topic
  • New Topic