I installed tomcat 9.0.40 on Windows 10 and deploy to it from Eclipse. The tomcat always responds with 404, even with all modifications I had introduced that I found in other posts.
Here is my current setup:
Eclipse server config, pointing to the configuration in Eclipse, using the tomcat installation path and deploying to webapps directory:
The server.xml from the Eclipse Server config uses port 8087, the webapps directory and shows the deployed context:
<Connector connectionTimeout="20000" port="8087" protocol="HTTP/1.1" redirectPort="8443"/>
...
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
...
<Context docBase="projects-topics-ws" path="/projects-topics-ws" reloadable="true" source="org.eclipse.jst.jee.server:projects-topics-ws"/></Host>
My Eclipse Server view shows the deployed webapp:
And the webapp is installed in the webapps directory:
In the Eclipse Project Facets I have checked "Dynamic Web Module 4.0" and "JAX-RS Webservice 2.1" but that doesn't seem to help either.
I can access the tomcat manager application at http://localhost:8087/manager/html and it shows my application as deployed and running.
Nevertheless, the tomcat responds with 404 if I access the application at the application base path http://localhost:8087/projects-topics-ws/, where it should respond with XML content.
Any ideas what I am missing?
Did you restart Tomcat?
The conf/server.xml is not reloaded after restart.
cite: 'The server.xml from the Eclipse Server': Check if the file is really evaluated ok (e.g. change port and restart server if you're not sure).
Your appBase is relative to $CATALINA_BASE directory, so you might want to double check that. It looks like it should be ok as the manager webapp seems working ok from same dir but I know some people having multiple servers installed in parallel and getting mislead by this.
Did you just check the base URL or also a specific (optimally static) resource from http://localhost:8087/projects-topics-ws/? e.g. http://localhost:8087/projects-topics-ws/html/index.html
Do you have a welcome page defined? If calling the base url, Tomcat will look for such file if defined:
<welcome-file-list>
<welcome-file>
index.html
</welcome-file>
</welcome-file-list>
Did you use the URL in browser or did you click on the path in the Tomcat management console, where it shows your deployed application? Is the path in the browser the same?
Related
I have a web app set up and running on Tomcat 8 with the project WAR file in the webapps folder in the tomcat directory. If i use any of the following links my project works fine
http://localhost:8066/myWebApp/home/
http://localhost:8066/myWebApp/booking/
http://localhost:8066/myWebApp/contactUs/
i want to set it so the above URL's work but also the following URL's which have /app added after the project name
http://localhost:8066/myWebApp/app/home/
http://localhost:8066/myWebApp/app/booking/
http://localhost:8066/myWebApp/app/contactUs/
i have set the path in the context.xml file as seen below
<Context docBase="myWebApp" path="/app" reloadable="true"> ... <Context>
but this does not work. am i doing this wrong or how can i go about doing this?
EDIT :
I can do this in eclipse by going to the server tab, opening the server and looking in the modules tab, so how do i do this on the Tomcat itself
You maybe use UrlRewriteFilter:
1. Add dependence
2. Change web.xml
3. Set rule in WEB-INF\urlrewrite.xml
or Rewrite.
We are deploying a webapp (.war file) from a legacy system where we have full control over our Tomcat instances to Amazon's Elastic Beanstalk instances.
On our own systems, we access the web app as a path (e.g. http://server-name/my-app if we deploy my-app.war), but Elastic Beanstalk renames our war-file to ROOT.war and hence makes the web app available under http://server-name, which breaks our existing applications.
As per the AWS documentation, we have added a config file under WEB-INF/.ebextensions that copies the following custom context.xml-file to /etc/tomcat7/Catalina/localhost/ROOT.xml:
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="localhost" docBase="" path="/my-app">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
We have tried different versions of this file, e.g. omitting docBase, specifying docBase="ROOT", using the aliases parameter etc., providing the full path to the ROOT directory etc., but none has made our WAR-file accessible under the /my-app path.
Finally, we also tried putting this <Context />-definition under the <Host /> section in server.xml, but to no avail. Any suggestions?
Update: when adding the following to server.xml under the <Host/>-definition, I'm able to access my-app under the correct path, but it seems that Tomcat on EB is deploying my application twice now:
<Context path="/my-app" docBase="ROOT/"></Context>
Although we can now access our app under the desired path, the application is still deployed twice by Tomcat. While this is a minor nuisance for us, I can imagine this being a problem on more resource-tight machines. On the plus side, we can now start migrating our apps to no longer use the resource path when accessing the API, which leads to cleaner and shorter API URLs.
I know it's two years late. But seems like disabling deployOnStartup will do the work.
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false" deployOnStartup="false">
I need to run my Java application on cPanel. I have successfully installed Tomcat,
I can run my application by copying war file into my www folder but the problem is that it shows the Project name (war file name) in the address, I need to know how to remove that, so users can access www.example.com rather than www.example.com/MyProject/index.jsp?
According to one cpanel hosting service command prompt access is generally turned off for cpanel for security reasons and you have to ask for it specifically. If you have this access you can login and run the unzip command (after uploading the war file using FileZilla or similar).
According to cpanel if you don't have command prompt access, you can upload the war to your public_html directory, but before doing this you need to change the apache config and add a "JkMount" for this (see the one with "appname" below).
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
JkMount /appname/* ajp13
</IfModule>
Except of course you put "your app name" instead of appname. This change will instruct apache to redirect calls to the top-level url (ie mydomain.com/appname) to your Tomcat instance (ie mydomain.com:8080/appname). After you have uploaded the war and changed the config, you have to restart apache.
But we said we didn't have ssh access, so how do we modify that file. according to this forum we can edit the /home/username/public_html/.htaccess or just /public_html/.htaccess and add these lines:
SetHandler jakarta-servlet
SetEnv JK_WORKER_NAME ajp13
Now, apache will re-direct to tomcat for mydomain.com/appname instead of mydomain.com:8080/appname. How do we get it to work from just mydomain.com? I simply don't know the answer to this. As far as I know using the usual trick of changing the war file to ROOT.war does not work in cpanel.
You will have to fix the entries at /usr/local/jakarta/tomcat/conf/server.xml Some time back after lot of tweaking I used this and it worked:
<Host name="domain.com" appBase="/home/username/public_html" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" reloadable="true">
<Alias>www.domain.com</Alias>
<Context path="" reloadable="true" docBase="/home/username/public_html" debug="1" privileged="true" autoDeploy="true" liveDeploy="true" />
<Context path="/manager" debug="0" privileged="true" docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>
A name of a war file has nothing to do how the project is presented by the container - it's just a matter of configuration and by default containers presents context path as a file name.
And using ROOT.war is just a silly trick, read about Context configuration in Tomcat (I have assumed you are using Tomcat)
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
There's several ways to set the application root context in tomcat. All of them described in the documentation of the server. Here's another one
Modify tomcat_home\conf\server.xml. Under the <Host tag put
<Context path="" docBase="yourappname" debug="0" reloadable="true" />
where you put yourappname.war in the webapps folder reflecting appBase attribute of the <Host tag.
Save, restart the server.
If you can't edit server.xml , Then you can delete ROOT.war and rename your war file to ROOT.war or just extract your .war file to a directory name ROOT.
Next time you open your site ex - www.example.com , index.jsp will be shown to you.
I have done the same for my site at Openshift which provides free PAAS service
they just need to unzip the .war archive in shell. See:
How to deploy a .WAR application - Ubiquity Web Hosting Wiki
We have over 100 users that have used these instructions and it works great. If you deployed Tomcat using EasyApache and have it setup as cPanel has designed, that should be about it. That was derived from:
http://twiki.cpanel.net/twiki/pub/Al...s08/Tomcat.pdf
http://forums.cpanel.net/f42/how-auto-deploy-war-cpanel-server-55096.html
I have set up a Postgres 9.0.1 SQL server and a Tomcat 5.5.28 both at my local PC. Both are running fine. But I have not been able to configure Tomcat to make the DataSource available via JNDI. I think I have followed the JNDI HOW-TO from the Tomcat pages to the letter (as well as having tried some other how-to's from other pages, too). But everytime Tomcat starts he displays the error message:
SEVERE: Null component Catalina:type=DataSource,path=/MyApp,host=localhost,class=javax.sql.DataSource,name="jdbc/postgres"
Tomcat does start nonetheless, but my database code won't work, because my InitialContext.lookup ends up with nothing.
The postgres driver "postgresql-8.4-701.jdbc4.jar" is copied into the following folders:
I:\Apache Software Foundation\Tomcat 5.5\common\lib
I:\Apache Software Foundation\Tomcat 5.5\webapps\MyApp\WEB-INF\lib
Here is my MyApp/META-INF/context.xml:
<Context path="/MyApp" docBase="MyApp" crossContext="true" reloadable="true" debug="1">
<Resource name="jdbc/postgres"
auth="Container"
type="javax.sql.DataSource"
username="postgres"
password="xxx"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost/MyDatabase"
maxWait="1000"
maxActive="20"
maxIdle="10">
</Resource>
</Context>
Here is an excerpt from my MyApp/WEB-INF/web.xml:
<web-app>
…
<resource-ref>
<description>
Postgres resource reference to a factory
</description>
<res-ref-name>
jdbc/postgres
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
</web-app>
My project is deployed as a WAR by Eclipse and Tomcat explodes the WAR at startup as a folder. Now the strange thing: If I doesn't start Tomcat by hand, but by Eclipse, everything works!!! Tomcat doesn't come up with the error message above.
I have discovered Eclipse uses its own server.xml, context.xml etc. when it starts Tomcat itself, but even after comparing those files with Tomcat's regular config files the only difference I have spotted so far is the following additional line in Eclipse's server.xml before the closing "host" tag:
<Context docBase="MyApp" path="/MyApp" reloadable="true" source="org.eclipse.jst.j2ee.server:MyApp"/>
But even when I copy this line into Tomcat's own server.xml (without the "source"-attribute), it doesn't work without Eclipse. So Eclipse must do something "extra" which makes finding the DataSource possible, while the "normal" Tomcat configuration fails. Since I have to deploy the WAR on a different server (without Eclipse) I need help to make this run without Eclipse. I think my code is ok, since it works fine with Eclipse's Tomcat, but my configuration of Tomcat 5.5 must be faulty. Any ideas?
After spending some more hours on the problem I have found a way to avoid Tomcat's error message. It seems my Eclipse configuration was faulty, because it was configured to add some of Tomcat's own jars into the folder "I:\Apache Software Foundation\Tomcat 5.5\webapps\MyApp\WEB-INF\lib". After I changed Eclipse's setting to not include them but to use those libraries as referenced ones, they weren't included in the WAR file anymore and Tomcat started without error. To be more precise, the following three jars being duplicated in the lib of my webapp had to be removed to avoid the message: "naming-factory.jar", "naming-factory-dbcp.jar" and "naming-resources.jar".
Interestingly, although Tomcat was starting fine now, the result remained the same: If started from within Eclipse, my webapp would succeed with the JNDI lookup for the datasource, but when I started Tomcat without using Eclipse, the webapp still would fail when trying to access the database with the error message below:
Cannot create JDBC driver of class '' for connect URL 'null'
It took me some more time to get this working, too. I had to give up on the preferred method of defining an app-specific datasource, but defined a global one instead. I still don't know WHY Tomcat refuses to understand my app-specific settings, but at least one can circumvent the problem. Following are the steps that solved all my problems and allowed me the JNDI lookup:
Modifying the server.xml file in %CATALINA_HOME%/conf/server.xml inside the tag "GlobalNamingResources": Here I added the complete "Resource" tag section that was already in my context.xml (see above).
Modifying the context.xml file in %CATALINA_HOME%/conf/context.xml inside the "Context" tag: Here I added the line: <ResourceLink global="jdbc/postgres" name="jdbc/postgres" type="javax.sql.DataSource"/>
I left the webapp-specific web.xml and context.xml unchanged (as seen above). Everything is working now. I post the solution to my problem I found myself in the hope others with a similar problem may benefit.
I have the following problem. When I developed my application locally I was deploying it using Netbeans support. Now I need to deploy the application on the official server. I installed Tomcat6 and it displays the start page properly but how to deploy my app? Which changes are needed to make ot work on port 80 (at the moment it works on default 8080)? Where should I copy the files from my application? Thanks a lot for helping me out. Links to similar posts are also appreciated. I could not find any that would help me tough.
how to deploy my app
Netbeans on build operation creates a war file in dist folder. See a question about it here. You will need to take this war file and:
Where should I copy the files from my
application?
put it under webapp folder in tomcat.
The location is your tomcat_home folder->webapps.
Which changes are needed to make to
work on port 80
under your tomcat_home folder, open conf folder. Inside, find server.xml file. open it with notepad and change the port number from 8080 to 80:
<Connector port="8080" … />
should be:
<Connector port="80" … />
Don't forget to restart the server!
Now the link to your application will be:
http://localhost/YourWarFileName/
or the computer ip/name instead of localhost.