This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First code compiling?

 
Shahnoor Ali
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shahnoor Ali
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shahnoor Ali
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic