File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Tomcat configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat configuration" Watch "Tomcat configuration" New topic
Author

Tomcat configuration

Doug Johnson
Greenhorn

Joined: Dec 13, 2012
Posts: 6
I am using Ubuntu 12.04 and installed Tomcat 7.0.34...apparently successfully. I also added the same server to my Eclipse (Juno) application.
I can get to the Tomcat welcome page both ways but nothing else works. I get 404 errors for every link from that page...docs, manager, etc. It does this from inside Eclipse as well as in a regular Firefox browser.
Am I missing somehing simple? I tried checking the logs but there isn't much there.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Hi Doug, welcome to JavaRanch!

Well, let's check the obvious first. Have you set JAVA_HOME and CATALINA_HOME? Did you set CATALINA_BASE to something other than the default? Are the directories docs, examples, manager, etc. under $CATALINA_HOME/webapps? What happens if you type: http://localhost:8080/docs into the URL?
Doug Johnson
Greenhorn

Joined: Dec 13, 2012
Posts: 6
Thanks.
When I start from the command line I get the following:
Using CATALINA_BASE: /home/kenneth/Tomcat7/apache-tomcat-7.0.34
Using CATALINA_HOME: /home/kenneth/Tomcat7/apache-tomcat-7.0.34
Using CATALINA_TMPDIR: /home/kenneth/Tomcat7/apache-tomcat-7.0.34/temp
Using JRE_HOME: /usr/lib/jvm/java-6-openjdk-amd64/jre
Using CLASSPATH: /home/kenneth/Tomcat7/apache-tomcat-7.0.34/bin/bootstrap.jar:/home/kenneth/Tomcat7/apache-tomcat-7.0.34/bin/tomcat-juli.jar

I didn't want to install in the default /usr/share directory as I was having issues with rights there...those are root only to modify. It was easier to put it in /home and I only need to be able to practice here at home with a working server.

JAVA_HOME is at: /usr/lib/jvm/java-6-sun. I changed that to /usr/lib/jvm/java-6-openjdk-amd64 but suspect that won't show up until I restart Ubuntu.
I am not sure what changed but now when I start the server either via command line or from Eclipse everything works fine in FF, but not in the Eclipse internal browser. Eclipse shows the welcome page but no links work. Correction: In FF the manager app worked once but now the link gives a 404 error. Manager/html and host-manager/html are not working now??? I tried restarting the server but still can't get the manager apps to work. changelog and release notes don't work either.

Strange how some are working, some not.

Thanks for any guidance/insight you can provide


Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Well, that's pretty baffling. It's possible that Eclipse isn't using the same environment settings that you are from the command line, but in that case, I don't see how you'd get to the intro page. It's consistent with folders /home/kenneth/Tomcat7/apache-tomcat-7.0.34/webapps (e.g., docs, example, manager) being missing, but I assumed you checked that already?
Doug Johnson
Greenhorn

Joined: Dec 13, 2012
Posts: 6
Yes, they are all in the webapps folder. I double-checked the paths to be sure they were correct as well. Is there a log somewhere besides 'logs' that might give me more of an idea of why it is getting the 404 message for those pages?
After restarting my computer I noticed that $JAVA_HOME is still pointing to java-6-sun. It is a complete installation and has all the directories that java-6-opejkd-amd64 has so I don't see why that might make a difference, but???

So far, today, it is working in both places. I have stopped and re-started the server from the command line and it is still working. Everything is working now in Eclipse as well. Maybe something caught up, maybe I just haven't done whatever it is I did before yet to break it??

I changed the Eclipse Server Locations setting to use the Tomcat installation instead of the workspace metadata (based on your observation re:environment settings) and that may have done the trick. It is still working when I start it from inside of Eclpse.

Thanks again for your time.

Doug
Antigoni Tsouri
Greenhorn

Joined: Dec 18, 2012
Posts: 8
Hey guys, I am having a similar problem with tomcat 6.0.36. It starts just fine, but can't find even the index.jsp, so I get a 404 error message.
Do you know how can I configure these variables such as CATALINA_BASE and the rest of them?

Thanks in advance!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15624
    
  15

You cannot just plunk an index.jsp file into the Tomcat webapps directory. The webapps directory is the container for webapps. As in "more than one webapp". Thus, each webapp is a subdirectory in WAR format (or a WAR file) within the Tomcat webapps directory (assuming default deployment rules).

To select which webapp - and thus which "index.jsp" file Tomcat will serve, your URL must contain a context path. Therefore: "http://localhost:8080/mywebapp1/index.jsp", for example. The default context path will be the name of your WAR directory.

The default settings for CATALINA_HOME and CATALINA_BASE, btw are the parent directory of the bin directory containing the tomcat commands.


Customer surveys are for companies who didn't pay proper attention to begin with.
Antigoni Tsouri
Greenhorn

Joined: Dec 18, 2012
Posts: 8
Tim first of all thanks for your reply.

Actually I am writing http://localhost:8080/TestTomcat/index.jsp, both in my eclipse, and in chrome (after of course I've started tomcat from eclipse) and the error I get is:
"HTTP Status 404 - /TestTomcat/index.jsp, description: The requested resource is not available."

The application is a simple application I created through eclipse New->Maven project->maven-archetype-webapp, and all it has is the default "Hello world" in the index.jsp file which is under the directory:
TestTomcat/src/main/webapp/index.jsp.

I'm sorry to ask you again, but it's he first time I try to configure apache-tomcat and first time I'm using eclipse, so I am completely lost! (Btw using eclipse juno(EE) and apache-tomcat-6.0.36)

I 've checked the web.xml also, but as far as I know it doesn't need any <servlet> or <servlet-mapping> to run the index.jsp from eclipse. The way I am running the program is right-click on it --> run on server.
I 've also configured the JAVA_HOME, CATALINA_HOME environment variables, and the PATH variable, and echoed them in the command line and they are set just fine.
I've changed the server location to "Use Tomcat Installations" through eclipse, to check that tomcat home page appears in the browser, works, but the http://localhost:8080/TestTomcat/index.jsp still doesn't.
I've restarted my eclipse and my PC and still nothing works!

Any help will be much appreciated because I don't even know where the problem is!

Thanks again for your time.
Doug Johnson
Greenhorn

Joined: Dec 13, 2012
Posts: 6
Probably already did this, but did you add the TestTomcat app to the server? Open the Servers tab, right click on the server, chose Add/Remove... and select TestTomcat fromt the left column, click on the add arrow in the middle. It should now be in the right column. Hit OK. Any luck?

Also, it could be where you put the .jsp file. My working install has it located in MyWebApp/WebContents/index.jsp. At least I think that is where I had it. Busy day today so I won't be able to get that system all rigged up to check.
Antigoni Tsouri
Greenhorn

Joined: Dec 18, 2012
Posts: 8
Doug thanks a lot!

Problem was fixed when I changed the index.jsp directory from ..../Webapp/index.jsp to ..../WebContent/index.jsp!
I already did the one with adding the project to the server by the way.

A last question, do you have any idea how can I change that working install?

Thanks a lot again, for I have been struggling two days now to find out what the problem was!
Doug Johnson
Greenhorn

Joined: Dec 13, 2012
Posts: 6
Do you mean where the .jsp file is stuck? That is the default place Tomcat expects to find it but if you get to the server options I think you can change the working directory to where ever you want probably. I am no expert though so I don't know what the side effects might be - it certainly would make it harder to move it to a different install. If you are just doing it like I did...just for learning purposes...I guess it would be OK!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15624
    
  15

J2EE - meaning webapps - does not have a "working directory". Using the stock Java working directory is done at your peril, since you never know what may be changing it externally and asynchronously.

EVERY J2EE webapp must be a WAR or an EAR (although Tomcat doesn't support EARs). These constructs have a definite directory layout, regardless of whether they are in standard (jar) or unzipped ("exploded") form. The webapp server must also assign a URL context to each webapp when it deploys the webapp. One - and only one - webapp can reside at the root context ("/"), however as shipped, Tomcat already has a webapp of its own installed there. All other contexts consist of one or more "directory names" which by default are the same name as their corresponding WAR.

It is true that you can store a WAR (in either JAR or exploded form) in alternative locations other than the TOMCAT_HOME/webapps directory, however, they still must be in WAR form, regardless.

tl;dr: You can't just plunk down files in a directory and expect it to work like a webapp.
Doug Johnson
Greenhorn

Joined: Dec 13, 2012
Posts: 6
I think I misspoke by referring to the 'working directory'. I am a pea-green newbie when it comes to J2EE. I am just transitioning from application programming and hopefully will learn something. I have been following along with the HeadFirst JSP book and it does show a pretty basic directory structure using Tomcat 5. I was just noting that I did get my single page to work by putting it all by itself in my (only) app directory. I haven't gotten to the creating a WAR parts yet but I do have mine set up with the structure described in the book. There is just nothing in any of the other folders yet.

In Eclipse there is a server setting titled Deploy Path which is what I think I meant to refer to. I assume you can use that to tell Tomcat where to look for your webapps if you don't use the default directory. I noticed that Eclipse created a much more complex directory structure when using Tomcat 7. Antigioni originally had his page in what I assume is the Java src file, which I am pretty sure is not where anything but java source files should go and is what I assume you meant...

J2EE - meaning webapps - does not have a "working directory". Using the stock Java working directory is done at your peril, since you never know what may be changing it externally and asynchronously.




Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15624
    
  15

Eclipse is not part of a webapp's run environment. Eclipse is a software development system and while it supports the creation and development of webapps, you won't find it anywhere near a production webserver in any sane IT shop. Just for the record, the WTP webapp plugin that comes with the Eclipse J2EE spin is an abomination, in my Humble Opinion. I use an alternative plugin (sysdeo). But that's not really relevant. The more important thing is that Eclipse settings don't count in the Real World.

A "Working Directory" is the directory where new files will be created or existing files will be located if a file open or create (or delete) is attempted via an unqualified relative pathname such as "myfile.txt". As mentioned, in J2EE, which directory this will be can change without notice, and therefore it is advisable to always use absolute pathnames when working with files in webapps.

The Working Directory is different than a Deployment Directory, which is a directory which contains one or more deployed webapps. The default deployment directory is TOMCAT_HOME/webapps, but this can be overridden on a per-webapp basis.

The Deployment Directory is also not the same thing as the webapp's root directory. Each webapp within a Deployment Directory MUST either be a WAR file OR it must be a WAR file exploded (unzipped) into a subdirectory of the Deployment Directory. J2EE does not support loose files just laying around in unstructured directories, and especially not in the root of a Deployment Directory. Exploded WARs are also not actually part of the J2EE standard, but many webapp servers support them. It's a configurable option in Tomcat, enabled by default.
Lamini Braveheart
Greenhorn

Joined: Dec 28, 2012
Posts: 2
Nicely said...

Thanks for keeping us straight :P It's harder to go off path when the road ahead is clear
 
jQuery in Action, 2nd edition
 
subject: Tomcat configuration
 
Similar Threads
Debugging a web appplication from Eclipse
Cannot start tomcat 3.3 from within eclipse
tomcat eclipse start issue
Jsf Error for simple jsf program in web application.
calling java inside a servlet