aspose file tools*
The moose likes Servlets and the fly likes Head First code compiling? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Head First code compiling?" Watch "Head First code compiling?" New topic
Author

Head First code compiling?

Shahnoor Ali
Greenhorn

Joined: Mar 26, 2010
Posts: 15
hi all
please help me compile my first servlet, i cant figure out how to compile the BeerSelect servlet code on page 80 of head first servlets, i have installed tomcat in D:\Tomcat\ and created the following environment variables

CATALINA_HOME d:\tomcat
CLASSPATH d:\tomcat\lib\servlet-api.jar;d:\tomcat\lib\jsp-api.jar
JAVA_HOME D:\Program Files\Java\jdk1.6.0_17
PATH D:\Program Files\Java\jdk1.6.0_17\bin

my project is created in this structure
c:\myprojects\beerv1\..(and the same development structure in the book)
so this gives my BeerSelect.java file the following location
c:\myprojects\beerv1\src\com\example\web\BeerSelect.java

but i cant figure out how to customize the following compile command given in the book,
javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java

please help me out!!!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

Shahnoor Ali wrote:/Users/bert/Applications2/tomcat/common/lib/servlet-api.jar

This is the only thing that looks specific to the book. What path do you have the servlet-api.jar file? Hint: the answer is in your post.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Shahnoor Ali
Greenhorn

Joined: Mar 26, 2010
Posts: 15
its d:/tomcat/lib/servlet-api.jar but still how do i use this path in the command???
should i use it like this...javac -classpath d:\tomcat\lib\servlet-api.jar:classes:. -d classes src/com/example/web/beerselect.java or how please tell, this small stuff is so annoying
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Shahnoor Ali wrote:its d:/tomcat/lib/servlet-api.jar but still how do i use this path in the command???
should i use it like this...javac -classpath d:\tomcat\lib\servlet-api.jar:classes:. -d classes src/com/example/web/beerselect.java or how please tell, this small stuff is so annoying

Well, the best thing is try it yourself, if any errors you may ask them here

And Welcome to JavaRanch, Shahnoor


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Shahnoor Ali
Greenhorn

Joined: Mar 26, 2010
Posts: 15
ughhhh the code gets compiled without using the classpath and servlet-api.jar and just by javac -d classes without any error, but you see i cant go any further without knowing exactly the right compiling procedure, and knowing why does it needs servlet-api.jar when it gets compiled without it so basically the question in my first post stands as it is, so please it would be gratifying if anyone can help and by the way, after trying all i could i joined this forum and asked the question
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

i mean whats the middle ;classes;. for??

That's another CLASSPATH entry for any class files the class being compiled depends on, if any.
Shahnoor Ali wrote:ughhhh the code gets compiled without using the classpath and servlet-api.jar and just by javac -d classes without any error,

That's because you already have CLASSPATH environment variable set for servlet-api.jar.
And by using complete command (i.e: with -classpath switch) it overrides the CLASSPATH entry. So you should add the entry for servlet-api.jar in that for the class to be compiled.
Shahnoor Ali
Greenhorn

Joined: Mar 26, 2010
Posts: 15
right! now i get it, thankyou vijitha, but i have one more silly question, the code for the listener class on page 173 would be compiled with the servlet compile command right? o and by the way i removed the the CLASSPATH variable from environment variables and then compiled the code with full path

package com.example;

import javax.servlet.*;

public class MyServletContextListener implements ServletContextListener {

public void contextInitialized(ServletContextEvent event) {
.
.
.
}
public void contextDestroyed(ServletContextEvent event) {
.
.
.
}

}
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Shahnoor Ali wrote:... the code for the listener class on page 173 would be compiled with the servlet compile command right?

If it doesn't contain any code which depends on other third party library, Yes it should.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First code compiling?