• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Compile a Servlet  RSS feed

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • 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: 38906
684
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21463
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the CLASSPATH variable.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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 IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you, now it works fine. I set the environment variable CLASSPATH.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!