This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile a Servlet

 
Urs Waefler
Ranch Hand
Posts: 77
  • 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?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
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: 77
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
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: 77
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the CLASSPATH variable.
 
Hemavathy Viswanathan
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.

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15492
43
Android IntelliJ IDE Java Scala Spring
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, now it works fine. I set the environment variable CLASSPATH.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic