Java Forum / First Aid / October 2004
can't find a class...
Frances Del Rio - 24 Oct 2004 03:04 GMT I'm trying to compile a servlet that contains the class currency.
classes imported are:
import java.io.*; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*;
. . . . . .
Currency dollars = Currency.getInstance(Locale.U.S.);
this is from a book, it's first servlet I'm trying to do (I have tomcat.. the book is a tomcat book...) when I try to compile I get told 'identifier expected'
C:\Documents and Settings\fdelrio\My Documents\tomcat-book>javac cc.java cc.java:22: <identifier> expected Currency dollars = Currency.getInstance(Locale.U.S.); ^ cc.java:22: ')' expected Currency dollars = Currency.getInstance(Locale.U.S.); ^ cc.java:23: <identifier> expected Currency pounds = Currency.getInstance(Locale.U.K.); ^ cc.java:23: ')' expected Currency pounds = Currency.getInstance(Locale.U.K.); ^
it says in the book on a side-note that 'currency' is a new class since version J2SDK 1.4... but I have version 1.4.2 (j2sdk1.4.2_05 to be exact..)
how do you find out exactly what classes come w/yr SDK/JRE? AND: the API that is at http://java.sun.com/j2se/1.4.2/docs/api/ corresponds to what version exactly? (full code of servlet is here.. http://www.francesdelrio.com/java/cc.html) thank you.. Frances
Paul Lutus - 24 Oct 2004 03:34 GMT > I'm trying to compile a servlet that contains the class currency. > [quoted text clipped - 17 lines] > cc.java:22: <identifier> expected > Currency dollars = Currency.getInstance(Locale.U.S.); Why not look into the documentation? Ask yourself if there is a locale named "U.S."?
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html#US
 Signature Paul Lutus http://www.arachnoid.com
Frances Del Rio - 24 Oct 2004 04:19 GMT >>I'm trying to compile a servlet that contains the class currency. >> [quoted text clipped - 22 lines] > > http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html#US thank you Paul, I fixed that error (and another error of mine in there too) and now it compiles fine... you know, I get confused here b/c when you compile servlets you have to always tell them where the servlet API is (obviously), but they also use classes from the 'regular' API that's posted at java.sun.. I still don't know if THAT API is included in tomcat (but it must, otherwise how would I use classes like java.io and java.util in servlets running on tomcat....) if I compile by doing
javac -classpath c:/tomcat/common/lib/servlet-api.jar cc.java (it's called 'servlet-api.jar' in my version of tomcat..)
it compiles ok, but if I set either CLASSPATH or Path to c:\tomcat\common\lib\servlet-api.jar
and compile thus:
javac cc.java
I get errors like this:
cc.java:16: cannot resolve symbol symbol : class HttpServletResponse location: class cc public void doGet(HttpServletRequest req, HttpServletResponse res)
and people in this ng wonder why I'm confused about CLASSPATH and Path!!!... ;) thank you for your response..
Frances
Tor Iver Wilhelmsen - 24 Oct 2004 09:30 GMT > javac cc.java
> symbol : class HttpServletResponse That class is not in the standard libraries in J2SE, which is what is on the classpath when compiling like that. You need to add the jars containing the servlet classes when compiling servlets.
Aki \ - 25 Oct 2004 08:36 GMT >>I'm trying to compile a servlet that contains the class currency. >> [quoted text clipped - 20 lines] > Why not look into the documentation? Ask yourself if there is a locale named > "U.S."? ...Probably not, since the dot (.) is a Java operator for accessing members of a class... So Currency.getInstance(Locale.U.S) would access member S of the (locale?) U.
 Signature -Aki "Sus" Laukkanen
Paul Lutus - 25 Oct 2004 08:48 GMT Aki "Sus" Laukkanen wrote:
/ ...
>>>C:\Documents and Settings\fdelrio\My Documents\tomcat-book>javac cc.java >>>cc.java:22: <identifier> expected [quoted text clipped - 6 lines] > members of a class... So Currency.getInstance(Locale.U.S) would access > member S of the (locale?) U. Yes. A little hand-holding here for the newbie. In any case, the original posted example is:
Currency dollars = Currency.getInstance(Locale.U.S.);
Which won't even compile in principle.
 Signature Paul Lutus http://www.arachnoid.com
Frances Del Rio - 24 Oct 2004 03:44 GMT btw, I did set the path for the servlet.. the book says to set CLASSPATH to c:\tomcat\common\lib\servlet.jar.. I set CLASSPATH and Path; folks in ths ng have told me not to set CLASSPATH.. does this also apply to tomcat?? ok, thanks again.. Frances
> I'm trying to compile a servlet that contains the class currency. > [quoted text clipped - 36 lines] > what version exactly? (full code of servlet is here.. > http://www.francesdelrio.com/java/cc.html) thank you.. Frances Tony Morris - 24 Oct 2004 09:34 GMT > I set CLASSPATH and Path; folks > in ths ng have told me not to set CLASSPATH.. does this also apply to > tomcat?? ok, thanks again.. Frances It is a good idea to never set your CLASSPATH environment variable. It won't be long before either; a) you have to learn what it means or b) you get stuck, and have to learn what it means (if you know what I'm saying). While you're there, learn about the -classpath compiler switch (which is what you *really* should be using).
Once you learn what it means, you should never set it - until then, start learning.
 Signature Tony Morris http://xdweb.net/~dibblego/
Frances Del Rio - 24 Oct 2004 15:32 GMT >>I set CLASSPATH and Path; folks >>in ths ng have told me not to set CLASSPATH.. does this also apply to [quoted text clipped - 8 lines] > Once you learn what it means, you should never set it - until then, start > learning. thank you very much for your response, Tony... ok, so: even if I use tomcat I don't need to set CLASSPATH? man, this is starting to drive me nuts.. so the only way for me to compile servlets is to type this long path every time?
javac -classpath c:/tomcat/common/lib/servlet-api.jar cc.java ?????
this is crazy.... why won't it work if I just add this path under Path???? (I mean where I have the path to the classes in SDK/JRE..)
(also, again: is the other API, the one that includes all other classes, like java.util, java.io, etc.. included in the tomcat? I'm assuming it is, but I'm not sure.. I see a lot other .jar files in C:\tomcat\common\lib but not rt.jar, which is where all classes are contained in my SDK/JRE.. according to what someone in this ng told me..)
also, why are the two servlet classes, javax.servlet and javax.servlet.http, not included in the 'regular' API?? I think it would make everyone's life a lot easier... ;)..
(PS: even though my servlet finally compiled fine I can't run it, get a standard "resource not found" when it tries to find the class, and what I don't understand here is that in the book the guy says the path to put for the class in the <form> tag is 'servlet/cc' (action="servlet/cc", cc.class is the class) when in fact full path to the class (where he says to put it) is
c:\tomcat\webapps\my-servlet\WEB-INF\classes\cc.class... (I tried putting this full path in form tag but it also wouldn't work..)
(path to form calling the class is c:\tomcat\webpass\my-servlet\cform.html) I put everyting where he says to put it..
I tell you, when I can finally run a servlet successfully I think I'm having a glass of champagne.... :) (but even if I successfully run a servlet at home am still not done, afterwards need to be able to run it at my new webhosting, which also has tomcat, need to set paths in unix, etc.. (they give you the paths -- for Path AND CLASSPATH, do I set CLASSPATH there?? will a lot of things be different? I mean b/c I'm assuming they don't have same version of tomcat I have.. man... life is complicated.. ok Tony, thank you very much for your help.. Francs
Oscar kind - 24 Oct 2004 16:52 GMT > [...] ok, so: even if I use > tomcat I don't need to set CLASSPATH? man, this is starting to drive me > nuts.. so the only way for me to compile servlets is to type this long > path every time? > > javac -classpath c:/tomcat/common/lib/servlet-api.jar cc.java ????? Not necessarily. There are several options (best first): 1. Add the library to the classpath when compiling with ANT. Depending on your preferences, this may also be number 2. 2. If you use an IDE, tell it to use that library for the project. 3. Create a little script for compiling.
The third option is basically a poor-man's version of option 1. But if you use ANT, you have a whole wealth of more options. It's also a lot easier to understand, but I'm not sure if that part is good enough to offset it's limitations.
> (also, again: is the other API, the one that includes all other > classes, like java.util, java.io, etc.. included in the tomcat? I'm > assuming it is, but I'm not sure.. I see a lot other .jar files in > C:\tomcat\common\lib but not rt.jar, which is where all classes are > contained in my SDK/JRE.. according to what someone in this ng told me..) No, but these classes are in the system API, which is always present. I'm not even sure the system API can be removed. IIRC, it cannot.
> also, why are the two servlet classes, javax.servlet and > javax.servlet.http, not included in the 'regular' API?? I think it > would make everyone's life a lot easier... ;).. Because the regular API doesn't include J2EE functionality. If it did include those classes, you'd compile an application against interfaces (e.g. HttpServletRequest) for which there is no implementation: that is provided by the container (such as Tomcat). Basically, you'd compile an unusable program.
> (PS: even though my servlet finally compiled fine I can't run it, get a > standard "resource not found" when it tries to find the class, and what [quoted text clipped - 5 lines] > c:\tomcat\webapps\my-servlet\WEB-INF\classes\cc.class... > (I tried putting this full path in form tag but it also wouldn't work..) I have never used Tomcat with classes in the default package. I'm not certain, but this may be the problem. What happens if you put the class in a package?
> I tell you, when I can finally run a servlet successfully I think I'm > having a glass of champagne.... :) It is a milestone. Especially if you get you application to run using a default installation (i.e. without changing the tomcat configuration). If you do, you've definitely earned it. :)
> (but even if I successfully run a > servlet at home am still not done, afterwards need to be able to run it [quoted text clipped - 3 lines] > assuming they don't have same version of tomcat I have.. man... life is > complicated.. This step is easy provided you got it working at home with these constraints: - Tomcat uses a default configuration - You package your web application in a .war file
The first constraint is the important one.
The second constraint is not necessary, but if you do you only have to copy one file instead of recursively copying an entire directory.
 Signature Oscar Kind http://home.hccnet.nl/okind/ Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
Frances Del Rio - 24 Oct 2004 17:56 GMT >>[...] ok, so: even if I use >>tomcat I don't need to set CLASSPATH? man, this is starting to drive me [quoted text clipped - 5 lines] > Not necessarily. There are several options (best first): > 1. Add the library to the classpath when compiling with ANT. "when compiling with ANT"??? Please, what is ANT... I just went to http://ant.apache.org/index.html it doesn't really explain what it is..
> Depending on your preferences, this may also be number 2. > 2. If you use an IDE, tell it to use that library for the project. > 3. Create a little script for compiling. I don't use an IDE either, all I use is a DOS shell, I can't compile a servlet from DOS shell w/o typing entire path to the classes? how come I can do it when compiling apps that run on my SDK/JRE??? why can't I compile by setting Path in control panel/system where you set env vars like you do for SDK/JRE????
>>(also, again: is the other API, the one that includes all other >>classes, like java.util, java.io, etc.. included in the tomcat? I'm [quoted text clipped - 4 lines] > No, but these classes are in the system API, which is always present. I'm > not even sure the system API can be removed. IIRC, it cannot. what is "system API"?
>>also, why are the two servlet classes, javax.servlet and >>javax.servlet.http, not included in the 'regular' API?? I think it >>would make everyone's life a lot easier... ;).. > > Because the regular API doesn't include J2EE functionality. what? what is J2EE??? (gosh, this is getting more complicated by the minute... I have SDK/JRE installed, how does this relate to J2EE???
ok, thank you again for your help... Frances
Oscar kind - 24 Oct 2004 19:15 GMT >> 1. Add the library to the classpath when compiling with ANT. > > "when compiling with ANT"??? > Please, what is ANT... I just went to http://ant.apache.org/index.html > it doesn't really explain what it is.. ANT is a build tool, somewhat like "make" is for C (but more powerful). A build tool does the compilation for you, handles dependencies between components, etc.
At work, we use ANT to: - Compile the application (with the classpath for the libraries we use); - Create the database creation script; - Update the version number; - Build a .jar or .war file; - Creates the javadocs; - Commits the new version file in CVS; - Tags the current version in CVS with the new version number; - Builds a zipped file fit for release.
As you can see, learning to use ANT is quite useful.
>> 2. If you use an IDE, tell it to use that library for the project. >> 3. Create a little script for compiling. [quoted text clipped - 4 lines] > compile by setting Path in control panel/system where you set env vars > like you do for SDK/JRE???? Not using an IDE is a good thing if you're learning. Keep it that way for now.
You may use the CLASSPATH variable, but AFAIK it is deprecated. Besides, you can also create a simple batch script (for Windows) like this:
@echo off javac -cp C:\path\to\servlets.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
This script calls the java compiler with a specific classpath, and any parameters you give to the script (ok, the first 9, but you'll rarely need more anyway). If you have more parameters you need to add for each compile, you can add them as well.
For Linux, the script looks like this:
#!/bin/bash javac -cp /path/to/servlets.jar "$@"
> what is "system API"? The API packaged with the JRE/SDK. This API is always availble. Others are not, and have to be added to the classpath explicitely.
It is better known as the Java API, but I felt that would be confusing at this point: other API's you encounter are also written in Java.
> what? what is J2EE??? (gosh, this is getting more complicated by the > minute... I have SDK/JRE installed, how does this relate to J2EE??? J2EE is an API to create "web applications", "enterprise java beans" and/or "enterprise applications". An application with servlets is a "web application". If it is combined with enterprise java beans (EJB's), it becomes an enterprise application.
Tomcat is a web application container. It allows you to create and run web applications, but not use the other parts of J2EE. The other terms are not important for now. You'll learn about them when you are ready to use them.
As for the the relation between the Java SDK and J2EE: J2EE is an API to be used in addition to the SDK. Also: - You installed the JDK, so you access to the system/Java API. - You have installed Tomcat, so you have access the J2EE API (or at least all the parts you can actually use with Tomcat).
 Signature Oscar Kind http://home.hccnet.nl/okind/ Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
Frances Del Rio - 24 Oct 2004 21:42 GMT >>>1. Add the library to the classpath when compiling with ANT. >> [quoted text clipped - 17 lines] > > As you can see, learning to use ANT is quite useful. you bet.............
>>>2. If you use an IDE, tell it to use that library for the project. >>>3. Create a little script for compiling. [quoted text clipped - 7 lines] > Not using an IDE is a good thing if you're learning. Keep it that way for > now. I know, I've been told.. :) (Is it like a WYSIWYG?? I hate WYSIWYGs..)
> You may use the CLASSPATH variable, but AFAIK it is deprecated. > Besides, you can also create a simple batch script (for Windows) like this: it's not that I particularly WANT to, I'm just truying to understand this classpath and path thing..
> @echo off > javac -cp C:\path\to\servlets.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 yes, I was thinking of doing a batch file for this.. I have just started lerning into batch files.. I did what you suggested.. entire file is
@echo off
javac -cp c:\tomcat\common\lib\servlet-api.jar %1 %2 %3 %4 %5
but when I try to run it a shell window opens and closes really fast and nothing happens.. (I do have tomcat turned on..)
>>what is "system API"? > [quoted text clipped - 3 lines] > It is better known as the Java API, but I felt that would be confusing at > this point: other API's you encounter are also written in Java. ok, so what I want to know is, is the system API included with tomcat?? (I'm assuming yes, b/c otherwise how could you use classes like java.util, java.text, etc in servlets, but I'm not assuming anything right now..) you say:
- You installed the JDK, so you access to the system/Java API. - You have installed Tomcat, so you have access the J2EE API (or at least all the parts you can actually use with Tomcat).
ok, so wait a min... when I compile a servlet specifying path to necessary classes in tomcat, from WHERE does it pull the classes in system API? (it must pull them from somewhere, it uses classes from system API..) so: let's say it pulls system API classes from JRE/SDK.. (is the path I have set for this sufficient for this??) then when I get to my hosting env, from where are system API classes pulled when I compile/run on hosting server? (I mean where my website is.. I just signed up w/a new JSP/servlet hosting a few days ago, haven't run any servlets yet..) they say to set classpath and java_home to:
CLASSPATH .:/usr/local/jsdk-1.3.1/lib/j2ee.jar JAVA_HOME /usr/local/jdk-1.3.1
(and note pls, they say CLASSPATH, not path, so: should I do this??)
>>what? what is J2EE??? (gosh, this is getting more complicated by the >>minute... I have SDK/JRE installed, how does this relate to J2EE??? [quoted text clipped - 3 lines] > application". If it is combined with enterprise java beans (EJB's), it > becomes an enterprise application. ok, but for functionality of servlets, for simple stuff like processing forms and such you don't need J2EE, right?? this still confuses me, I'm still trying to understand what java beans are and what enterprise is.. so again,
> J2EE is an API to create "web applications"... servlets are web applications, JSP's are web applications, right??.. ok, I need to move on to what I really need to know right now,like I still can't run my servlet even though I have finally managed to compile it ('by hand', typing in entire path..) I get a standard "resource not found" when it tries to find the class, and what I don't understand here is that in the book the guy says the path to put for the class in the <form> tag is 'servlet/cc' (action="servlet/cc", cc.class is the class) when in fact full path to the class (where he says to put it) is
c:\tomcat\webapps\my-servlet\WEB-INF\classes\cc.class... (I tried putting this full path in form tag but it also wouldn't work..)
(path to form calling the class is c:\tomcat\webpass\my-servlet\cform.html) I put everyting where he says to put it..
I wanted to be able to successfully compile and run a servlet this weekend.. still trying... Oscar, many thanks for your help.. Frances
Oscar kind - 25 Oct 2004 05:50 GMT >> Not using an IDE is a good thing if you're learning. Keep it that way for >> now. > > I know, I've been told.. :) (Is it like a WYSIWYG?? I hate WYSIWYGs..) Not really. GUI editors can be, but I don't use them. An IDE's primary use is to do menial tasks for you to make you more productive. This is a blessing for programmers who know what the IDE does for them. It is not useful for beginners, as they also need to learn those things. If the IDE does it for them, they won't learn.
>> You may use the CLASSPATH variable, but AFAIK it is deprecated. >> Besides, you can also create a simple batch script (for Windows) like this: > > it's not that I particularly WANT to, I'm just truying to understand > this classpath and path thing.. The path used by the system is where the system looks for executables. The classpath is where Java looks for classes.
>> @echo off >> javac -cp C:\path\to\servlets.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 [quoted text clipped - 9 lines] > but when I try to run it a shell window opens and closes really fast and > nothing happens.. (I do have tomcat turned on..) Ah, you've run it by double-clicking it. This script is too simple for that. Call this script as you would call the java compiler (with the classes to compile as an argument). Then it'll work.
>> The API packaged with the JRE/SDK. This API is always availble. Others are >> not, and have to be added to the classpath explicitely. [quoted text clipped - 6 lines] > java.util, java.text, etc in servlets, but I'm not assuming anything > right now..) No. The system API is silently included in the classpath by the JRE/SDK. That's why Tomcat needs the SDK installed: not just for the compiler and JRE, but also for the system classes.
> ok, so wait a min... when I compile a servlet specifying path to > necessary classes in tomcat, from WHERE does it pull the classes in > system API? (it must pull them from somewhere, it uses classes from > system API..) As stated above, it silently adds them to the classpath, and pulls them from the installation (most likely %JAVA_HOME%\jre\lib\rt.jar).
> so: let's say it pulls system API classes from JRE/SDK.. > (is the path I have set for this sufficient for this??) then when I get > to my hosting env, from where are system API classes pulled when I > compile/run on hosting server? (I mean where my website is.. I just > signed up w/a new JSP/servlet hosting a few days ago, haven't run any > servlets yet..) In the hosting environment, the JRE does the same thing as on your computer: it silently adds the system API from wherever it is installed (assuming noone moved it after installation), adds it to the classpath, etc.
> they say to set classpath and java_home to: > > CLASSPATH .:/usr/local/jsdk-1.3.1/lib/j2ee.jar > JAVA_HOME /usr/local/jdk-1.3.1 > > (and note pls, they say CLASSPATH, not path, so: should I do this??) If they say so: do this. These are specific installation instructions for deployment at their server. For your home machine, try not to do this for the environment of Tomcat.
>> J2EE is an API to create "web applications", "enterprise java beans" >> and/or "enterprise applications". An application with servlets is a "web [quoted text clipped - 4 lines] > forms and such you don't need J2EE, right?? this still confuses me, I'm > still trying to understand what java beans are and what enterprise is.. This is far from simple. The simplest would be to create a command line program. First one that has it's parameters hard-coded, then one that parses either command line arguments or user input.
To compare:
For a command line application you need to: - Have a basic understanding of Java - Implement what you want the application to do - Parse user input - Know how to invoke the java runtime
For a web application you need to: - Have a basic understanding of Java - Implement what you want the application to do - Parse user input - Have a basic understanding of J2EE/web applications - Know about HTML - Know how HTML form values are represented by the request - Know how to deploy a web application - Know how to configure a J2EE container such as Tomcat (because your hosting provider appearently doesn't have a default installation).
Note that the first three items are the same.
> > J2EE is an API to create "web applications"... > > servlets are web applications, JSP's are web applications, right??.. Yes.
> ok, I need to move on to what I really need to know right now,like I > still can't run my servlet even though I have finally managed to compile [quoted text clipped - 9 lines] > (path to form calling the class is > c:\tomcat\webpass\my-servlet\cform.html) Compilation goes well. Deployment doesn't.
The locations used within a web application is NOT the location on disk: it is the location on the server (i.e. what you type in the address bar of your browser).
I still think your problem is that Tomcat cannot find a class in the default package (which is where you put cc now). What happens is you put it in another package, say com.fdr? The location of the servlet as known by the form would then be "servlet/com.fdr.cc".
 Signature Oscar Kind http://home.hccnet.nl/okind/ Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
Andrew Thompson - 25 Oct 2004 07:19 GMT (Frances Del Rio)
>> @echo off >> >> javac -cp c:\tomcat\common\lib\servlet-api.jar %1 %2 %3 %4 %5 rem: try this line instead. rem: redirect output to file.. javac -cp c:\tomcat\common\lib\servlet-api.jar %1 %2 %3 %4 %5 >op.txt
>> but when I try to run it a shell window opens and closes really fast rem: then keep the command line window open pause
>> ..and >> nothing happens.. .. 'Something' always happens, it is a matter of figuring out what did happen, then making it happen the way you want.
> Ah, you've run it by double-clicking it. This script is too simple for > that. Call this script as you would call the java compiler (with the > classes to compile as an argument). Then it'll work. Good idea..
 Signature Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane
Bryce - 25 Oct 2004 15:57 GMT >> Not using an IDE is a good thing if you're learning. Keep it that way for >> now. > >I know, I've been told.. :) (Is it like a WYSIWYG?? I hate WYSIWYGs..) You are confusing an IDE with an IDE that had GUI building tools. IDEs are handy in that they make a lot of mundane tasks easier.
For example:
When you compile your application in a DOS window, you need to append the classpath. In my IDE (and most IDE's have similar functions), I make a Java project, and add the libraries to the projects properties (in Eclipse, go to project properties -> Java Build Path -> Libraries Tab, and add additional Jars for that project. Now, whenever I compile, It happens immediately.
Using ANT provides similar functionality. If you prefer to compile on the command line, then Ant allows you to script your build process. Similar to writing a DOS bat file, but is a lot more conducive to building Java programs. And example similar to yours would have a build.xml file like this:
<project name="My Servlet" default="compile" basedir="."> <path id="my.classpath"> <pathelement path="path.to.my.servlet.jar"/> </path>
<target name="compile" description="compiles"> <javac srcdir="src" destdir="build" classpathref="my.classpath" includes="**/*.java"/> </target> </project>
This is just a very simple example. Other things Ant (and IDEs as well) do is deploy to Tomcat, start Tomcat, run Java applications, you name it.
-- now with more cowbell
John Fereira - 28 Oct 2004 01:09 GMT >>>>1. Add the library to the classpath when compiling with ANT. >>> [quoted text clipped - 20 lines] > > you bet............. I also strongly recommend using Ant.
Take a look at some of the Jakarta projects and you'll find that all of them use Ant to compile, deploy, build the documentation, and create distributions. I also use it for running unit tests and have even used to for xml/xslt transformations to turn documents written in xml into pdf files.
If you're writing java servlets, I recommend reading the following page:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/appdev/index.html
While it is for Tomcat 4.1, it's mostly applicable for Tomcat 5.0 and describes how to set up a build directory, where to put source code other files necessary for building a web application. Then use Ant with that recommended directory structure to build and deploy applications.
Juha Laiho - 31 Oct 2004 23:54 GMT Frances Del Rio <fdr58@yahoo.com> said:
>ok, but for functionality of servlets, for simple stuff like processing >forms and such you don't need J2EE, right?? this still confuses me, I'm >still trying to understand what java beans are and what enterprise is.. Servlets are part of the full J2EE specifiation, so in that sense you do need J2EE for servlets. But then, J2EE is vastly more than just servlets and JSPs.
Forget 'enterprise' for a good while; so even if formally you're using J2EE by writing servlet/JSP applications, let's just say you're writing servlet/JSP applications, and not fuss about the J2EE.
As for Java Beans, they're objects modelled according to a simple set of principles (and not to be confused with "Enterprise Java Beans", which are something different, and usually not so simple).
Beans (regular, not EJB) should be considered as a bunch of related data fields with methods to set and retrieve the values of individual fields (instead of providing direct access to the field values). So, you might have
public class Person { private Float weight; private Float height;
public Float getWeight() { return this.weight; }
public void setWeight(Float w) { this.weight=w; }
// and similarly for height }
... and this is a Java Bean in its most basic form: - it has private data fields - it has non-private methods to get/set values of the fields (and the method names correspond to the names of the data fields, with the exception of the regular change in capitalization) - no parameters for the get-methods - void return type for the set-methods - read-only fields are supported, by simply not providing the set*() -method (but then, the value must be set using some other way; in class constructor, as constant value, or as a side effect of setting some other data field) - "virtual" fields are also allowed (and these would be good candidates for read-only fields); so, the above class could have a getWeightIndex() method (to return the weight index for the person, calculated from the stored weight and height, but not stored anywhere)
The published interface (set of get- and set- methods) is the most important feature of a Java Bean. Internals can be implemented in whichever way is seen suitable.
So, a Java Bean is a very nice, very basic object. At first it looks like it's too simple to be of any real use, but surprisingly it is rather handy in suitable cases (and the more advanced forms do quite a lot of magic behind the get/set -method scene).
 Signature Wolf a.k.a. Juha Laiho Espoo, Finland (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++ "...cancel my subscription to the resurrection!" (Jim Morrison)
Frances Del Rio - 24 Oct 2004 18:16 GMT can't dl ANT.. http://ant.apache.org/
any mirror I try to dl from browser/downloader crashes when it reaches 99%... they don't have a 'contact' link... so that takes care of that... :( Frances
any suggestions???
>>[...] ok, so: even if I use >>tomcat I don't need to set CLASSPATH? man, this is starting to drive me [quoted text clipped - 71 lines] > The second constraint is not necessary, but if you do you only have to > copy one file instead of recursively copying an entire directory. Bryce - 25 Oct 2004 15:59 GMT >can't dl ANT.. http://ant.apache.org/ > >any mirror I try to dl from browser/downloader crashes when it reaches >99%... they don't have a 'contact' link... so that takes care of >that... :( Frances try again maybe?
>>>[...] ok, so: even if I use >>>tomcat I don't need to set CLASSPATH? man, this is starting to drive me [quoted text clipped - 71 lines] >> The second constraint is not necessary, but if you do you only have to >> copy one file instead of recursively copying an entire directory. -- now with more cowbell
Bryce - 25 Oct 2004 15:48 GMT >>>I set CLASSPATH and Path; folks >>>in ths ng have told me not to set CLASSPATH.. does this also apply to [quoted text clipped - 15 lines] > > javac -classpath c:/tomcat/common/lib/servlet-api.jar cc.java ????? Yes. As we discussed a few weeks ago, Java needs to know where to find the classes. Tomcat knows where its libraries are, so you don't need to set it for it.
>this is crazy.... why won't it work if I just add this path under >Path???? (I mean where I have the path to the classes in SDK/JRE..) sigh... Path is an OS entity. Java needs its own CLASSPATH entity to find libraries that are not included in the standard distribution. The reason we tell you not to set CLASSPATH is because its best to specify on the command line.
>(also, again: is the other API, the one that includes all other >classes, like java.util, java.io, etc.. included in the tomcat? I'm >assuming it is, but I'm not sure.. I see a lot other .jar files in >C:\tomcat\common\lib but not rt.jar, which is where all classes are >contained in my SDK/JRE.. according to what someone in this ng told me..) NO. Because just like you don't need to include the other classes in your classpath when you run your standalone java apps, Tomcat uses the standard java distribution you have installed.
>also, why are the two servlet classes, javax.servlet and >javax.servlet.http, not included in the 'regular' API?? I think it >would make everyone's life a lot easier... ;).. Sun decision. They've split it all into multiple distributions. Those people only developing standalone applications have no need for the J2EE stuff (which is where the servlet stuff is). If you need that stuff, then its trivial to include them.
>(PS: even though my servlet finally compiled fine I can't run it, get a >standard "resource not found" when it tries to find the class, and what >I don't understand here is that in the book the guy says the path to put >for the class in the <form> tag is 'servlet/cc' (action="servlet/cc", >cc.class is the class) when in fact full path to the class (where he >says to put it) is Well, did the book say anything about what to put in your web.xml file?
>c:\tomcat\webapps\my-servlet\WEB-INF\classes\cc.class... Sell, if you are saying the action is "servlet/cc" then there needs to be a mapping in your web.xml file letting Tomcat know to mapp any requests coming in for "servlet/cc" to your class.
>(I tried putting this full path in form tag but it also wouldn't work..) > [quoted text clipped - 10 lines] >assuming they don't have same version of tomcat I have.. man... life is >complicated.. ok Tony, thank you very much for your help.. Francs -- now with more cowbell
John Fereira - 28 Oct 2004 00:58 GMT >>>I set CLASSPATH and Path; folks >>>in ths ng have told me not to set CLASSPATH.. does this also apply to [quoted text clipped - 13 lines] > me nuts.. so the only way for me to compile servlets is to type this > long path every time? Check out the Jakarta Ant build tool. It makes compiling and deploying servlets to Tomcat much easier.
> javac -classpath c:/tomcat/common/lib/servlet-api.jar cc.java ????? > [quoted text clipped - 7 lines] > contained in my SDK/JRE.. according to what someone in this ng told > me..) When Tomcat is started it requires that the %JAVA_HOME% environment variable be set. Once it has that it can figure out where the SDK libraries are.
When your servlet executes using Tomcat, the servlet container (Tomcat) will load classes from several locations. It finds rt.jar or whatever from the JAVA_HOME variable, looks in common\lib for jar files that are common for all contexts running under tomcat, and in the webapps\AppName\WEB-INF\lib for jar files required by the servlet you've developed. It finds the classes for the servlet in webapps\AppName\WEB-INF\classes or, if you bundle up all the classes for servlets in the context into a jar file it can be put in webapps\AppName\WEB-INF\lib.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|