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

Facing problem in compiling the first servlet program

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to compile this simple servlet program from head first java,but i m stuck

Following,whatever is there in the book,I set the classpath
like this javac -classpath C:\ApacheSoftwareFoundation\tomcat5.5\common\lib\servlet-api.jar -d classes src\Ch1Servlet.java
1.package javax.servlet.http.* does not exist
2.cannot find symbol HttpServlet.

Please Help...
 
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at this: http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html and http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html
 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Charles

Thanks for that link,i have set the classpath according to that but still its giving the same error
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Geet,
Try this .. right click your MyComputer icon on desktop. Goto -> Advanced Tab. There you will find Environmental variables
click on that you will find all the system variables lis over there.
In UserVariables section you can create environmental variables. Now click on new
1) variable name : classpath

value :<path till lib of insatalled java>e.g(C:\Program Files\Java\jdk1.5.0\lib);.;<path till lib of tomcat> e.g(C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib);<path till jsp-api.jar>;<path till servlet-api.jar>e.g(C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jsp-api.jar);.;

after writing this all click ok. Your classpath environmental variable will be created which you can see it in the list.
2)variable name : path

value: <path till bin of installed java>;<path till bin of tomcat>
click ok to create this variable.

3)variable name :CATALINA_HOME
value :<path till tomcat base> e.g(C:\Program Files\Apache Software Foundation\Tomcat 6.0)
4)variable name : JAVA_HOME
value : <path till java base> e.g(C:\Program Files\Java\jdk1.5.0)

Now apply these variables and compile your program your program will be compiled
Regards
 
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure why you can't you IDE like Eclipse which is freely available and creating a simple servlet class doesn't take more than a minute through wizard. I'm not trying to force to use IDE but it looks like you are working on Servelts recently. So, why not start with an easier approach?

Cheers,
Naren

----------------------
SCJP
SCDJWS
SCWCD
----------------------
 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Mahesh

you were a great help,and i followed your instructions step by step
crossed my fingers,but still no use,its not compiling yet again...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As this is more about learning to compile than it is about Servlets, it's been moved to a more appropriate location.
 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Naren

Just wanted to be familiar with this approach first,and then would think of switching to the IDE
 
mahesh shastri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Geet ,
May I know what exactly you are doing ? If I guess you might be adding classpath clause while compiling.
Actually goto to your project dir then to WEB-INF . Now use javac -d classes src\<ClassName.java>. It will create
.class file in classes folder but classes folder should be there under WEB-INF\classes
Hope it will work now
Regards
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:. . . it's been moved to a more appropriate location.

I thought this thread looked unfamiliar, and was wondering why nobody has yet given the correct way to set a system classpath-not at all.

Advice that you ought to set a system-wide classpath is usually mistaken; you should set a classpath for each application with the -cp flag.
 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Mahesh

I am Compiling the program from the project directory first,once it gets compiled only then do i need to copy n paste it in the web-inf-classes folder,as told in the book
but as i see,going by the same i am not able to compile it.
 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey campbell
Thanks for your advice,but if you could ellaborate it,as it would be of great help...
 
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:
  • Quote
  • Report post to moderator

geet kaur wrote:like this javac -classpath C:\ApacheSoftwareFoundation\tomcat5.5\common\lib\servlet-api.jar -d classes src\Ch1Servlet.java
1.package javax.servlet.http.* does not exist
2.cannot find symbol HttpServlet.


Are you sure that the directory "C:\ApacheSoftwareFoundation\tomcat5.5\common\lib" exists and contains a file named servlet-api.jar?

You're not just leaving out the spaces in the path, are you? Because "C:\ApacheSoftwareFoundation" is not the same as "C:\Apache Software Foundation". If the directory name contains spaces, enclose the name in quotes, for example:

javac -classpath "C:\Apache Software Foundation\tomcat5.5\common\lib\servlet-api.jar" -d classes src\Ch1Servlet.java
 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jesper
I am setting the classpath like
javac -classpath C:\ProgramFiles\ApacheSoftwareFoundation\Tomcat5.5\common\lib\servlet-api.jar
I am not putting in any spaces in the path.

But Again i am getting this same error
 
mahesh shastri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Geet
As young said there must be gaps between folder name. I think it should be c:\Program Files\Apache Software Foundation.
Try to copy path from address bar when you access those folder and paste it while compiling on command promt.
Other thing javac -d classes will create .class file in classes folder. you dont need to copy. Let me know what exactly you are
doing.

Regards
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

geet kaur wrote:Hey campbell
Thanks for your advice,but if you could ellaborate it,as it would be of great help...

If you set a system classpath, all applications will use it. Even though they require different classpaths. So a system classpath will grow and grow. Set your classpath as Jesper has told you; if you create a jar, put the classpath in its manifest file.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi geet, you can try like this on command prompt its working for me.

C:\<tomcat root directory>\webapps\<your application folder>\WEB-INF>javac -cp "<tomcat root directory>\lib\servlet-api.jar";. -d classes src\Ch1Servlet.java

here "." in -cp represent system defined classpath. java compiler(javac) will first look HttpServlet class in servlet-api.jar and after that it looks in all jar files which are set in system defined classpath
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic