• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How put a Tomcat 7 app folder outside webapps (OS X)?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have Tomcat 7.0.37 running under OS X 10.8.3 (Mountain Lion) with mod_proxy_ajp connector to Apache 2.2 httpd on localhost. My webapps folder is set in Tomcat's conf/server.xml to /Users/myname/Sites/webapps, and URL tomcat.local works just fine, as in httpd-vhsosts.conf I added item:

And Tomcat's conf/serverl/xml specifies: <Engine name="Catalina" defaultHost="localhost">...<Host name="localhost" appBase="/Users/myname/Sites/webapps" ...</Host></Engine>

Then to access Tomcat, URL tomcat.local also works, as in /private/etc/hosts I have entry: 127.0.0.1 tomcat.local

If inside my (non-default location) webapps I place the Tomcat app webMathematica in a subfolder webmathematica, then I can access it OK with URL http://localhost:8080/webmathematica.

How can I successfully put the whole webmathematica folder outside the webapps folder and access it in the browser, as say webmathematica.local?

Here's what I tried:

1. Inside the tomcat folder /conf/Catalina/localhost I put file webmathematica.local.xml consisting of:
<Context docBase="/Users/myname/Sites/webmathematica.local"></Context>

2. To /private/etc/hosts I added entry: 127.0.0.1 webmathematica.local

But URL http://localhost:8080/webmathematica.local gives a Tomcat 404 error "The requested resource is not available."
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to be conflating the domain URL with the context path.

If mathematica.local is mapped as localhost, you'd use it as the domain, and give your web app a more customary context path. Or make it the ROOT web app if you don't want a context path; but I usually don't recommend that. And I don't see why you're dickering with hosts (see below).

Here's an example from my setup (Tomcat 6, but I imagine Tomcat 7 setup is similar):

$TOMCAT/conf/Catalina/localhost/testbed.xml contains:

which makes the web app available at: http://localhost:8080/testbed

If my machine were configured with the name bear, the web app would also be available at http://bear.local:8080/testbed. No configuration in hosts necessary thanks to Bonjour.
 
Murray Eisenberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You seem to be conflating the domain URL with the context path.

If mathematica.local is mapped as localhost, you'd use it as the domain, and give your web app a more customary context path. Or make it the ROOT web app if you don't want a context path; but I usually don't recommend that. And I don't see why you're dickering with hosts (see below).

Here's an example from my setup (Tomcat 6, but I imagine Tomcat 7 setup is similar):

$TOMCAT/conf/Catalina/localhost/testbed.xml contains:

which makes the web app available at: http://localhost:8080/testbed

If my machine were configured with the name bear, the web app would also be available at http://bear.local:8080/testbed. No configuration in hosts necessary thanks to Bonjour.



OK, I removed the mathematica.local entry from hosts and in $TOMCAT/conf/Catalina/localhost/mathematica.local.xml added the apparently missing item path="/Users/myname/Sites/webmathematica.local" (I had had only the docBase="/Users/myname/Sites/webmathematica.local" item there).

But after restarting Tomcat and apache and emptying the Safari browser cache, still URL http://localhost:8080/webmathematica.local gives error "The requested resource is not available."

(As I originally said, if I put the webmathematica folder inside my docBase (as specified in $TOMCAT/conf/server.xml), then this Tomcat app works OK.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Murray Eisenberg wrote:and in $TOMCAT/conf/Catalina/localhost/mathematica.local.xml added the apparently missing item path="/Users/myname/Sites/webmathematica.local" (I had had only the docBase="/Users/myname/Sites/webmathematica.local" item there).


Not correct. The path should be the context path, not a file path. And I would drop the ".local" from it; I don't even know if a period is allowed, but even if so, it's certainly not customary.

And settle on one name. It's just asking for trouble using "webmathematica" in some places, and "mathematica" in others. I'll assume "webmathematica" for now, in which case, the path value (and hence the context path) should be "/webmathematica", and the file name should be webmathematica.xml.

Upon restarting Tomcat, fire up the Tomcat manager app and see if the web app is even deployed. If it's not, there's no sense doing anything else until it is.
 
Murray Eisenberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Murray Eisenberg wrote:and in $TOMCAT/conf/Catalina/localhost/mathematica.local.xml added the apparently missing item path="/Users/myname/Sites/webmathematica.local" (I had had only the docBase="/Users/myname/Sites/webmathematica.local" item there).


Not correct. The path should be the context path, not a file path. And I would drop the ".local" from it; I don't even know if a period is allowed, but even if so, it's certainly not customary.

And settle on one name. It's just asking for trouble using "webmathematica" in some places, and "mathematica" in others. I'll assume "webmathematica" for now, in which case, the path value (and hence the context path) should be "/webmathematica", and the file name should be webmathematica.xml.

Upon restarting Tomcat, fire up the Tomcat manager app and see if the web app is even deployed. If it's not, there's no sense doing anything else until it is.


Sorry for any typo: "mathematica" should be "webmathematica"-- and is so in the file.

Evidently I don't understand what I should be setting for path. What should it be given the rest of my setup?

I did delete the ".local" suffix from webmathematica.local, and renamed webmathematica.local.xml and the app's directory accordingly, but still doesn't work after restarting tomcat.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Murray Eisenberg wrote:Evidently I don't understand what I should be setting for path. What should it be given the rest of my setup?


It's the other way around -- you choose a context path and match the setup to it. The context path is the means by which the many web apps hosted by Tomcat are distinguished; each by its own context path. So one Tomcat server can host /webmathematica, /testbed, /puttintame, /mywonderfulapp, /whatever, and so on.

You decide upon the context path, "/webmathematica" in this case, and name the xml config file accordingly as webmathematica.xml. Within the file, the path is defined as "/webmathematica".

When Tomcat starts, it will create a web app (known as a context) with the path /webmathematica. The context path precedes the servlet path in all URLs that address the web app.

I did delete the ".local" suffix from webmathematica.local, and renamed webmathematica.local.xml and the app's directory accordingly, but still doesn't work after restarting tomcat.


Does the manager app show that the web app is even running?
 
Murray Eisenberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Murray Eisenberg wrote:Evidently I don't understand what I should be setting for path. What should it be given the rest of my setup?


It's the other way around -- you choose a context path and match the setup to it. The context path is the means by which the many web apps hosted by Tomcat are distinguished; each by its own context path. So one Tomcat server can host /webmathematica, /testbed, /puttintame, /mywonderfulapp, /whatever, and so on.

You decide upon the context path, "/webmathematica" in this case, and name the xml config file accordingly as webmathematica.xml. Within the file, the path is defined as "/webmathematica".

When Tomcat starts, it will create a web app (known as a context) with the path /webmathematica. The context path precedes the servlet path in all URLs that address the web app.

I did delete the ".local" suffix from webmathematica.local, and renamed webmathematica.local.xml and the app's directory accordingly, but still doesn't work after restarting tomcat.


Does the manager app show that the web app is even running?


OK, I set path="/webmathematica" element in webmathatica.xml. If I restart tomcat and look at its Web Application Manager, it gives error:

and lists "/webmathematica" among the Applications but says its not running. (But I knew that already!) If I click the Start button there, I get the same error.

I emphasize that this app is OK in itself: if I discard the webmathematica.xml file and put the whole webmathematica folder inside the webapps folder, then after restarting tomcat the app works.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anything in the logs before the failure messages?
 
Murray Eisenberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Anything in the logs before the failure messages?


Not sure which log files to examine. Nothing today in tomcat.local-error_log (which I specified as the error log file in https-vhosts.conf).

In tomcat.local-acess_log (also specified in https-vhosts.conf), before time of last failure, have:

In /usr/local/apache-tomcat-7.0.37/logs/catalina.2013-05-06.log, I see:
For reference, here's the current webmathematica.xml:
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm, well its certainly not starting the context. Nothing in the logs before that? Usually when I've seen that, it's because a context listener or class loader failed.

 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dumb question #213: there really is a properly formed web app at /MacHD/Users/murray/Sites/webmathematica, right?
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A web server is not a file server. The "directories" in a URL are not filesystem directories. They merely share a common syntax with the Unix filesystem.

In a 100% pure web application, the application is entirely contained within a WAR, which is an extended form of ZIP file. Note that a WAR itself is a file, not a directory, and the "directories" and "files" within the WAR are simply index definitions, not actual filesystem components that can be opened, read, written, and otherwise treated as first-class filesystem objects. I realize that the issue gets blurred in several ways (some extended filesystems do have limited ability to peer inside a ZIPfile, many webservers can explode a WAR), but the basic common denominator should not assume such amenities.

When a URL is submitted from a client to a webapp server, the webabb server breaks it down into component parts which tell it which webapp to forward the request to. The webapp's WEB-INF/web.xml (for J2EE webapps) contains rules that further extend this routing to a specified servlet. If the incoming URL matches none of the specified URL patterns, then the webapp server contains an invisible "default servlet" which will take over and further dissect the URL, trying to match it up with a JSP or - if all else fails - a resource path within the WAR. If the URL is matched to a resource path, the default servlet will open that resource and copy its contents to the HTTPServletRequest response data stream.

Thus, to access (read) any resource external to a WAR, you need a servlet that can act as intermediary to the webapp that will perform the same function as the default servlet, but using whatever alternative resource location that servlet specifies. Mapping to that servlet is controlled via the URL pattern matching in the web.xml file, and any relationship between the incoming URL and any directory/file paths served up by this user-written servlet are solely determined by the servlet itself.

And of course, the standard caveat: Whatever you do, don't attempt to upload data into a WAR. Even if it works, you will regret it. Always upload into a directory that is both external to the WAR and to the webapp server.
 
Murray Eisenberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Dumb question #213: there really is a properly formed web app at /MacHD/Users/murray/Sites/webmathematica, right?


Yes, there is! (And not at all an unreasonable thing to verify.)

The proof: If I place the whole webmathematica folder inside the Tomcat webapps folder I can access it and get it to run from URL http://localhost:8080/webmathematica.

Note: A comment on the mathematica.stackexchange.com forum suggested putting in the webapps folder a symlink to the separate webmathematica folder in another location. With that symlink, I was able to access the app -- but not to be able to create some alias-like URL to it, e.g., "localhost/webmathematica" or "webmathematica" as I have, without success, been trying to do by using a $TOMCAT_HOME/conf/Catalina/localhost/webmathematica.xml file with an appropriate Context element.
 
Murray Eisenberg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:A web server is not a file server. The "directories" in a URL are not filesystem directories. They merely share a common syntax with the Unix filesystem.

In a 100% pure web application, the application is entirely contained within a WAR, which is an extended form of ZIP file. Note that a WAR itself is a file, not a directory, and the "directories" and "files" within the WAR are simply index definitions....


Sorry, I don't understand the relevance of all that to the question I posed. The webmathematica folder, as distributed by Wolfram Research, is a fully-formed Tomcat app, including a .war, a top-level index.html, Java servlets and JSP's, a WEB-INF subfolder with a web.xml, etc. And if it's dropped inside Tomcat's webapps folder it works just fine.

I'm trying "merely" to be able to (1) put the webmathematica folder elsewhere; and (2) be able to access it by a simple alias-like URL of my devising (all right now strictly for localhost use).
 
Tim Holloway
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Your question resembled another frequently-asked question.

You do not deploy a J2EE webapp by dropping a folder with a WAR inside it into the TOMCAT webapps directory (or anywhere else). The WAR file is the webapp. If you have a folder with both a WEB-INF and a .war file inside it, it is some sort of Frankenstein hybrid, because a folder with a WEB-INF inside of it fits the basic pattern of a WAR and a .war file isn't really a WAR unless it has a WEB-INF inside of it. I'd go on about exploded WARs versus standard WARs and so forth, but that's immaterial here.

Regardless. On closer examination, I, too question the idea of putting a ".local" in the context pathname. If you feel the need, I'd recommend "-local", instead, although on the open Internet, dash-names have gone out of style even though they remain syntactically valid.

You appear to be confusing hostnames and context names. You do not define context names in a hosts file (or DNS or whatever). Context names are sub-paths within the URLs directed to a server, so only the Context xml file applies to them. Handling of the Hostname/port part of a URL is done (mostly by the client!) in order to steer the URL request to Tomcat. Tomcat then takes the context part of the URL to determine which webapp within it should receive the request in accordance with the rules I spelled out above. So remove the /private/etc/hosts entry. It doesn't apply.

Also, if you are using a ":8080" port in your URL, you are bypassing Apache. So the Apache ajp config stuff isn't important here either.

The actual context of a webapp deployed via conf/Catalina/localhost is the name of the Context file, less the ".xml" extension. If the Context file doesn't have an ".xml" extension, if won't be deployed. Further, it's the name of the file that gets used, not the "path=" attribute value.

So I recommend renaming the context file to "webmathematica.xml" and seeing what comes up at "http://localhost:8080/webmathethematica/".
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim, I think you're kinda covering old ground. It's clear from previous posts that the file is named webmathematica.xml already.

That said, I'm rather mystified at this point. I do this all the time (albeit with Tomcat 6) and never have a problem deploying web apps.
 
Tim Holloway
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Tim, I think you're kinda covering old ground. It's clear from previous posts that the file is named webmathematica.xml already.

That said, I'm rather mystified at this point. I do this all the time (albeit with Tomcat 6) and never have a problem deploying web apps.



Yeah. Sorry about that. Reading stuff from a screen I tend to get things garbled. Especially when the question superficially looks like a FAQ. I can enumerate the rules at work, and I can recommend how to build up from a valid WAR, but deconstructing something that's already trying to be everything already assembled can be a real challenge. Especially since we are likely to miss the place where they zigged when we expect to see a zag.
 
reply
    Bookmark Topic Watch Topic
  • New Topic