Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't find servlet-api.jar

 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all....

I'm trying to compile a servlet class with the following command:
(This is issued from the directory that contains Beer.java)

javac -cp \Apache\Apache\lib\servlet-api.jar:. -d \Apache\Apache\webapps\Duran\WEB-INF\classes Beer.java
These are my errors:

package javax.servlet does not exist
package javax.servlet.http does not exist
and it cannot find HttpServletRequest,HttpServletResponse,ServletException and HttpServlet.


I have set TOMCAT_HOME and JAVA_HOME...
For a stand-alone servlet class...what must be included in the classpath?
 
Gurjit Sandhu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Servlet can be compiled the same way as any other Java source file. You can compile it from the command line using javac, or if you are using an integrated development environment.

(IDE), use the IDE’s compile command or menu option. You will need to include the
correct Java EE library for the compilation. There are two possible libraries to choose from,depending on whether you are using the Java EE reference implementation, the Tomcat server,or JBoss. It doesn’t matter which one you use.

If you have the Java EE SDK, you can use the javaee.jar library;

if you have Tomcat or JBoss , you can use servlet-api.jar.

For example, if you’re using the Java EE reference implementation, assuming JAVAEE_HOME is the environment variable for the location of the Java EE SDK, you could compile the Servlet with the following command line on Windows systems:

> javac –classpath %JAVAEEHOME%\lib\javaee.jar Login.java

On Linux and Unix systems, you would use this command line:
> javac –classpath $JAVAEEHOME/lib/javaee.jar Login.java

If you’re using Tomcat 5, assuming CATALINA_HOME is the location of the Tomcat installation,on Windows systems, compile the Servlet with the following command:

> javac –classpath %CATALINA_HOME%\common\lib\servlet-api.jar Login.java

On Linux and Unix systems, use this command:
> javac –classpath $CATALINA_HOME/common/lib/servlet-api.jar Login.java
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips:

but as you can see TOMCAT_HOME was already defined explicitly in my classpath.
But it is nice to know that I can use \%CATALINA_HOME\lib in the future...
Will the %CATALINA_HOME work if I have defined the environmental variable as TOMCAT HOME??
Maybe the issue is that I didn't include the underscore in TOMCAT HOME...
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh my gosh...I just got it working by removing the . from the cp....
I didn't know that specifying redundant paths would cause compilation to fail!!!

Thanks for your efforts!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic