• 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

Compile a Servlet

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to compile a servlet like this:

javac myFirstServlet.java

It does not work, it get the following message:

package javax.servlet does not exist

How can I compile a servlet?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Urs,
javax.servlet is part of Java EE not Java SE. Your server (Tomcat, JBoss, etc) comes with a file called j2ee.jar or servlet.jar. Add this to your classpath when compiling.
 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know, that javax.servlet is not part of Java SE. I use Apache Tomcat. I found servlet.jar. So far so good.

How shall I continue?

This is the path:

C:\Programme\Apache Software Foundation\Tomcat 6.0\lib\servlet.jar

javac -classpath C:\Programme\Apache Software Foundation\Tomcat 6.0\lib\servlet.jar myFirstServlet.java

Is it something like that? Or do I have to copy servlet.jar in folder lib of the jdk?

Till now it does not work.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do not copy the jar file anywhere. You can include it in the classpath in-place. Otherwise you risk jars getting out of sync with each other.
 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now it worked, I could compile it. I did it like that:

set classpath=C:\Programme\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar

Then:

javac myFirstServlet.java

But I do not want to enter the first line always. Is it possible to set it in the operating system, in Microsoft Windows XP you can set in System the variables.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the CLASSPATH variable.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can set the CLASSPATH as either a user variable or system variable. As the name says, if it is set as a user variable, it is available for the particular user. If it is set as a system variable, the classpath is available to all.

 
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
See this entry in the FAQ: Compiling Servlets
 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, now it works fine. I set the environment variable CLASSPATH.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic