So I'm getting to know Eclipse and Java and wanted to learn more about JSP development. For the life of me, no matter what tutorials I follow on ADC, IBM etc, I can't get a simple JSP running in Tomcat.
What I can accomplish:
-Get tomcat running, get it launched from the Eclipse Sysdeo plugin.
-Get a normal java application compiled and running in Eclipse, then export it and run it in Terminal.
Questions:
-Do I need to install any other JDK-related resources on my machine (above and beyond anything already provided on the Mac.) for JSPs?
-Any special configuration: environment variables, classpath, Eclipse preferences that need to be set for Eclipse?
It's slightly depressing that alot of the learning guides and resources out there already assume you have your environment set up so tomcat can support JSP's you put in WEBAPP, but it does not seem that straightforward on Mac.
Karen Zeller wrote:-Do I need to install any other JDK-related resources on my machine (above and beyond anything already provided on the Mac.) for JSPs?
No. Tomcat works just fine on Macs just like any other platform.
-Any special configuration: environment variables, classpath, Eclipse preferences that need to be set for Eclipse?
I do not know -- which is why I've moved this post to the IDEs forum. This is much more an Eclipse issue than a Mac issue.
It's slightly depressing that alot of the learning guides and resources out there already assume you have your environment set up so tomcat can support JSP's you put in WEBAPP, but it does not seem that straightforward on Mac.
Tomcat supports JSPs right out of the box, Mac or otherwise.
According to the instructions, I've put it under my tomcat/webapps folder and unzipped it, creating a sample.war folder in the directory.
When I stop and restart Tomcat, and go to http://localhost:8080/sample, I get a "description The requested resource (/sample) is not available." What could this possibly be when I've got Tomcat up and running and am getting the 'happy cat" + congratulations you've got Tomcat successfully set up message at localhost:8080.
There's nothing at the empty path "/". If you look at the deployment descriptor (web.xml) you'll see there's a servlet mapped to "/hello". Go there instead.
Edit: Well, there's an index.html file I didn't see... try typing the index.html name in manually. If that also doesn't work, then there's probably a deployment issue--check the logs.
This message was edited 1 time. Last update was at by David Newton
Maybe I just don't "really" get Tomcat. Maybe I did a failed install/unpacking. So now that I've gone back to this problem today and try to see what is going on, I get these errors when I try to start up Tomcat in Eclipse:
Feb 8, 2010 2:36:52 PM org.apache.catalina.startup.ContextConfig applicationWebConfig
SEVERE: Parse error in application web.xml file at jndi:/localhost/Beer-v1/WEB-INF/web.xml
org.xml.sax.SAXParseException: Open quote is expected for attribute "{1}" associated with an element type "xmlns".
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1642)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:365)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1072)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4377)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Feb 8, 2010 2:36:52 PM org.apache.catalina.startup.ContextConfig applicationWebConfig
SEVERE: Occurred at line 1 column 16
Feb 8, 2010 2:36:52 PM org.apache.catalina.startup.ContextConfig start
SEVERE: Marking this application unavailable due to previous error(s)
Feb 8, 2010 2:36:52 PM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Feb 8, 2010 2:36:52 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/Beer-v1] startup failed due to previous errors
So I originally unzipped Tomcat at:
../../Applications/tomcat/
And the webapps/Beer-v1 has a form.html as well as a /WEB-INF with web.xml as a DD in it:
When I also tried to go to Terminal and cd to Tomcat then say sudo bin/startup.sh, I get a "command not found" error. This is odd because if I look in the bin directory there is a startup.sh there.
Just a couple days ago when I was trying to deploy the sample JSP on Tomcat, at least it ran with out errors on startup.
Oh, so I got this resolved. When I cut and paste the web.xml from the book I am learning from, it used curved quotes not real " causing the parse error. So I can indeed see a basic HTML form.
It appears like the earlier example I was playing with the other day was done back when you did not also include a web.xml DD, I'm guessing? The instructions were just to put the .jar in webapps.
You can deploy more than one application to the webapps directory. When you start the application server (tomcat in this case) in addition to everything else it does during start-up, it will also attempt to start any deployed web applications. So probably what happened was:
1. You started the application server, and it started successfully;
2. You copied a malformed web application to the webapps directory, and the application was not able to start;
3. You stopped and attempted to restart the application server. When it got to the point where it tried to start each of the web applications, it tripped again over the malformed one.
This is probably why you got an error at start-up when you didn't before.
As for the Jar that you were instructed to copy to the webapps directory, have a look inside it. If it's a web application, it will have a WEB-INF folder and a web.xml file in that.
I use Eclipse on Windows with JBoss application server. When you start the application server from within Eclipse, it does its own start - you cannot also go to the command line and run the start up shell script. I expect it will work the same in your environment.
At this point, do you still have any problems, or is everything working and you're able to continue on with your tutorials?
Thanks for the help. That clarifies what was going on. Now I can launch tomcat and get the HTML form.
Now I am stuck on the next step of the tutorial where I compile the BeerSelect.java class. I get these errors:
MatthiasMacBookProesktop admin$ javac BeerSelect.java
BeerSelect.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
BeerSelect.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
BeerSelect.java:5: cannot find symbol
symbol: class HttpServlet public class BeerSelect extends HttpServlet {
^
BeerSelect.java:6: cannot find symbol
symbol : class HttpServletRequest location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request,
^
BeerSelect.java:7: cannot find symbol
symbol : class HttpServletResponse location: class com.example.web.BeerSelect
HttpServletResponse response)
^
BeerSelect.java:8: cannot find symbol
symbol : class ServletException location: class com.example.web.BeerSelect
throws IOException, ServletException {
When you use Eclipse to build the application, you will tell it which application environment you wish to target, and it will automatically include the proper Jar files on the build classpath. If you want to build from the command line, then you will need to include these jars yourself. They will be provided by Tomcat, but as I don't use that particular application server, I can't tell you specifically which ones. However, you can inspect the Jar files yourself and see which once contain the classes. You'll find there will probably be one or two that have all the classes required by a client application, and you'll just need to include them.
If you need help finding the specific Jar files, have a look at the Tomcat documentation. It will probably mention this in the section on classpath setting for build environments. For JBoss, they have a directory called 'client', and in that directory there is (among many others) a Jar named jbossall-client.jar which has everything needed. Perhaps Tomcat has something similar?
By the way, if you enclose your console output in code tags, it will be much more readable.
Although it is legal to set CLASSPATH using relative path names (as you have shown above), this will break if you change the location from where you execute your build. Instead, you may want to utilize fully-qualified path names.
Note that I'm not familiar with the Mac environment, so you may know more about this than I do. In my environments (Windows and UNIX), I set the CLASSPATH such that it is set regardless of where I'm working (I set it in the environment I get when I create a shell, so it's always there for me).
So I don't see how this CLASSPATH is incorrectly set at all (do you see any errors?), and I still get the compile errors. Are these in two other tomcat jars other than the ones I am referencing in classpath?
Unfortunately not. I sure has heck could not find it with ease under the tomcat 6.0 documentation. Were they to have had search for their site, it would be perhaps be easier. It was not under their "develop your first JSP" section (ironically.)
I notice this was an issue a while back noted in the JavaRanch Forums:
You can just inspect the Jar files yourself. Do you have a Zip file view utility on Mac, like WinZip?
Alternatively, you can use the jar utility to do it, using the list command line argument, like:
If you have to, you can even create a temporary directory and extract the Jar file there, then just look at the files with any utility you like.
This is what I meant by find the Jar files that contain the classes required by your build.
You'll want to start looking in the Tomcat distribution. Like I said earlier, there's probably a directory for client Jars, and within that, there's probably one or two Jar files that contain everything you need. However, I don't use Tomcat, so I can't point you to the exact Jar files. If you were using JBoss ...
I completely understand that I need a classes in these two jars in order for my servlet to compile. It's a pretty simple servlet:
------
package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class BeerSelect extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html") ;
PrintWriter out = response.getWriter() ;
out.println("Beer Selection Advice<br>") ;
String c = request.getParameter("color") ;
out.println("<br>Got beer color " + c) ;
}
}
-----
So when I look in servlet-api.jar, I find :
----
7656 Tue Jan 19 14:39:46 PST 2010 javax/servlet/http/HttpServlet.class
1420 Tue Jan 19 14:39:46 PST 2010 javax/servlet/http/HttpServletRequest.class
--------
which are among the classes that javac is throwing up errors about in spite of them being in the jar.
So the basic question are:
-Error in Classpath and therefore javac cannot get to the .jars I need to compile?
-Error in the import statements?
-Do I need to unarchive the .jars themselves for their classes to be available?
I've been going around in CIRCLES for hours trying to compile
As an alternative, can I IMPORT these two jars into Eclipse and get thing compiled?
Karen (going slowly insane by this) Zeller
This message was edited 1 time. Last update was at by Karen Zeller
Again, you may want to make more use of the code tags. It will make some output much more readable.
That appears to be the Jar you want, so I would guess there is something wrong with the way you're setting CLASSPATH. Try specifying the classpath on the command line to javac, using the -classpath argument.
So I have BeerSelect on my Desktop, navigate to it and do this:
Really thinking I'm going insane at this point.
The -classpath argument is expecting a single parameter, but you're trying to give it two.
Also, are you sure the correct path separator character on the Mac is the semicolon? I think it's the same as UNIX, which is the colon.
So, try this instead:
Note: Adjust the separator character if I'm wrong about that.
Oops, I think I was wrong: I'm guessing the semicolon is the command separator on Mac. So the javac command terminated at the semicolon.
It never saw the second Jar or the source file.