Spring don't work on war deployed with Tomcat - java

I have a rare problem, at least for me.
I have a project built in Java. Using Maven and Spring MVC. I define a couple of controllers to redirect between pages (.JSP).
I deploy my WAR project on Tomcat webapps folder. And everything seems fine.
Now when I access to the app from the server local IP (192.168...), everything works.
But, when I access from public IP, the only thing I get is the folders of the project, it's like the context configuration of Spring and controllers doesn't work.
Of course, I can to navigate to each page with the complete URL.
Already checked that both directions also point in the same folder.
Thanks in advance.
EDITED
I want to say that I configure apache and tomcat connector. So When I enter to my local IP with the :8080, my app works fine. But when I enter without it, I see the list of folders.
EDITED 2
My web server is Apache.
And my connector configuration is:
workers.properties:
worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
/etc/apache2/mods-available/tomcat_connector.conf:
<IfModule jk_module>
# Tomcat Connector custom properties
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/jk.log
JkShmFile /var/log/apache2/mod_jk.shm
JkLogLevel error
JkMount /manager/* worker1
JkMount /host-manager/* worker1
</IfModule>
And the only thing that I add to /etc/apache2/sites-available/default is:
JkMountCopy On
I get some information from this tutorial:
http://blog.sourcerebels.com/post/28254180614/usar-apache-como-frontal-de-tomcat-en-ubuntu-server
Thanks!

Related

Jhipster apache tomcat install

I'm using JHipster to build a web application (awesome project, keep going guys :).
I'm using a server where apache is already installed deploying a php app (http://www.myurl.com)
I'm trying to deploy my JHipster app under another url (http://www.myurl.com/my_project)
I tried :
rewrite rule to redirect /my_project http://localhost:PORT/my_project using my own tomcat install
using runnable jhipster war
changing some cong in yml file to add context under server > context-path
Nothing is working fine :
access to first page webapp ok but 404 to any other pages
blank page, unable to load resources because context is missing I think
doesn't change anything
Any other idea? Something I forget? Something related to webpack ?
Thanks for any help :)
Use apache(httpd) proxying to redirect calls to your jHipster application to your tomcat
the configuration is meant to be put in apache configuration files you must have proxying mod enabled in apache but if my memories are good proxying user sessions from apache httpd to tomcat can be quite tricky. The following syntax is what you are looking for
ProxyPass "/images" "http://www.example.com/"
ProxyPassReverse "/images" "http://www.example.com/"
https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html

how to configure Embedded Tomcat virtual host for Spring Boot Application?

i have a multiple domains on my centos vps (domains running on apache http server via virtual host configurations). and also same vps, i want to add my new domain but that domain will route my spring boot application (application is a jar file also inside embedded tomcat ). i couldn't find any configuration for embedded tomcat specific domains and ports.
standalone Tomcat i can make configuration via server.xml file like this image
also this short tutorial shows configuration for stadalone tomcat Tomcat Virtual Host Configuration
But how can i do that configuration for embedded Tomcat ? Any suggestion ?
With Spring Boot embedded Tomcat, you are hosting only one application per servlet container. So I don't believe that Tomcat's concept of Virtual Hosts make sense at all.
If you have to host your app on shared Tomcat instance, just build WAR without embedded container.
It depends. 2 ways to deploy your project.jar as you want to :
First way : You can use the "apache web server" and his own "mod_proxy" in order to serve as many Spring webapps you want to, each on a specific port configured with "php-fpm" and with a proxy defined to route requests from/to your namebased VirtualHost configuration.
Nowadays, with Spring Boot 2.5, all you have to do is to set the property server.port in your application.properties file, and use it accordingly with mod_proxy directives.
If you are using profile, you can either set one port to dev or prod or test or whatever properties file you need.
Another way to proceed : you can use the apache web server "mod_jk" bridge module to configure multiple load-balancers for your Virtualhosts too.
Choose your path, young Jedi ;)
This response is certainly not for the OP, 7 years later, but for other people whom are using any web search engine like Google. They will come here and see "something is impossible". It is not true.

how to manage multiple war application in tomcat server?

I use tomcat as web server,I want to deploy many same war file in tomcat server with different config. How to do this in the best way possible manner?
So I want to run tomcat server per each war application, my means is tomcat1 handle the .war1 in webapp and ... or handle all war files with one tomcat?which one is better?
Change the names of your war files and deploy
Use the same tomcat server, but copy and rename your web application to something different. For eg, the original application name app, copy and rename as following.
webapp -> app1
app2
app3
Running a different tomcat server for each war application might not be necessary.

How to set context path in Tomcat so one could enter the site without appending the deployed folder name?

I read about this on Tomcat guide here and some SO questions. And I think I'm pretty much doing the same thing. But in some way cannot manage to succeed.
First of all I have to say that my application is deployed on a shared Tomcat server that I have no control over. I just drop my .war file and it gets deployed.
I tried to package my application as ROOT.war but didn't work. The admin told me to package it as whatever the name I want and they would take care of it.
I packaged it as my-application.war and it got deployed but I have to enter http://my-host/my-application to get to the website.
After contacting the admin they told me that they have put a context elemnt in my host in Tomcat config file like:
<Context path="" docBase="path of my-application deployed folder"/>
which was supposed to set my-application as default application for all the requests coming to my-host. But it didn't and whenever I enter http://my-host I get:
HTTP Status 404 - / The requested resource (/) is not available
But again when I enter http://my-host/my-application it all works fine. Any suggestion on what might be wrong is definitely appreciated.
Updates:
I tried to follow the steps described in tomcat documentation on how to make the application default. 3 ways are described and I tried all three ways and could successfully deploy my application as ROOT on localhost.
I also tried to reproduce the problem I'm facing on remote server so I could find the reason and report it to admin. I find couple of problems.
In server.xml fragment that admin sent me autoDeploy and deployOnStartUp are set to true, whereas they should be false if explicitly defining Context element in server.xml. This will cause double deployment which creates a ROOT folder and a folder with the name of the .war file. Deleting the .war will delete it's corresponding folder and undeploys the application but ROOT remains and must be deleted manually and requires a Tomcat restart. Until it's restarted any deployment of ROOT.war will fail.
I figured there are some reasons preventing ROOT.war from deploying. One could be that a ROOT.xml exists in conf/{engine-name}/{host-name} or a ROOT folder exists in appBase of the host or as I described above a ROOT application from previous deployment is not undeployed and requires Tomcat restart.
Either way I couldn't exactly pinpoint what exactly is preventing ROOT.war from deploying since that requires the access to Tomcat log files and conf files to check the cases I described above.
Also from all I see my the admin seems incapable of maintaining a Tomcat server and finding the problem. So I decided to go with a dedicated Tomcat server after struggling with the shared one.
In your question, you state that the admin set the context as:
<Context path="" docBase="path of my-application deployed folder"/>
Based on the comments above, I would suggest trying to use the relative path of your application rather than the absolute path.
I tried this on my tomcat server with:
<Context path="/" docBase="my-application/" />
and that did the trick.
The Host element which contains the Context element does actually set some parameters that might also impact the context. If it's the default settings, then a relative context should simply point to the webapps folder. If it's been changed, the results may vary.
Usually this can be achieved by the following steps:
Define a ROOT.xml context file in conf/Catalina/localhost
Name your webapp WAR “ROOT.war” or containing folder “ROOT”
However, i doubt you will be able to do that on a shared Tomcat instance. Only one application can run as the default application. The hosting company will probably not allow it as otherwise which application will they allow to be the default out of the many people sharing the same Tomcat instance?
See this link : http://staraphd.blogspot.com/2009/10/change-default-root-folder-in-tomcat.html
The Tomcat Wiki has a section on putting applications into default context.
However, in order to do this it implies some control over the Tomcat server that may not be possible in the shared context you describe.
If you have the ability to install other systems on the server, one alternate solution would be to use a proxy server like NGINX. This is way more complicated than simply naming your war file ROOT.war, but sometimes it's the only option.
If you have NGINX listening on the server and you have your own url, you use the HttpProxyModule with setting such as:
server {
listen 80;
server_name my.domain.com;
location / {
proxy_pass http://my-host/my-application;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
Also in order to make this work, you'd have to own the "my.domain.com" url and it would need to be separate from the one everyone is using for the shared Tomcat server.
The nginx portion of the solution is free, but if you need to register a new url and then use something like no-ip.com to redirect it to the tomcat server it would cost money.

How to work with a shared Tomcat?

Sorry, but I tried searching for this subject, but I didn't find related to my problem.
Recently, I bought a domain and web hosting for it. I bought it especially for using it for my Java projects.
I have Tomcat available as server on the hosting.
My question is: how do I work with a hosted Tomcat, which, in my opinion, it is quite different from localhost (where you could have unlimited access)?
For example, if I create a Spring project that looks like this:
project-name
src
war
index.jsp
WEB-INF
web.xml
The index.jsp outputs a simple This is a test
web.xml
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
I created an Ant build.xml that will build the project, but when I access from http://domain.com/project-name it will not work, and I only cand access the file from http://domain.com/project-name/war
If I had done this on localhost, I'd deploy it in tomcat-path/webapps, but how does this work online?
The solution is to install Tomcat Manager Webapp in order to deploy applications on a shared hosting that uses Tomcat as server.
EDIT:
If the hosting doesn't offer you Tomcat Manager (as was in my case), you can still make it through by asking the administrator of your hosting to configure your jk_mod file to deploy your war files.
Append these lines
jkMount /*.war ajp3
jkMount /* ajp3 ## I'm still not sure if this made it work, because it makes tomcat listen on the entire public_html
But be aware, if your version of Tomcat is brought to you by cPanel's EasyApache, you will have to deal with some issues there too - the latest installed Tomcat will be 5.5.33 (a bit old, right?), but again you can try tweaking the old version and install, let's say 6.x.x
A tutorial about this upgrade:
http://www.bestdesigns.co.in/blog/install-tomcat-6
The thing that help me a lot to understand the concepts that were envolved in solving this problem:
http://www.scribd.com/doc/6085698/Tomcat -- a training course about Tomcat and cPanel
An another thing to add: Install a local version of Tomcat on your machine, first deploy it on localhost. If there it works, it should be working online as well.
Those of you who work with Spring Roo, on Tomcat 5.5.33, if you already know, you cannot deploy your projects, becase of the too old Tomcat, so you have to upgrade your Tomcat immediately.
I hope this will help all of those who had difficulties like myself.

Categories

Resources