Tomcat server won't start if my servlet references another project - java

I currently have 2 java projects that should be working together. The first project, Controllers, contains classes that should establish a connection to my database and communicate with it.
The second project is a dynamic web project with a servlet and 2 jsps(LoginPage and Welcomepage). The servlet uses the objects in the controller project to connect to the database, verify that a user's username and password are correct, and send them to a welcome screen.
Here's where it gets weird. As soon as I attempt to declare an object defined in my cotrollers project, my server refuses to start. It gives no error other than "Server Tomcat v9.0 Server at localhost failed to start." I have verified that my server works, I have checked that the build path is configured correctly, I have even commented out all the code in the controller object being defined. It's as if the mere act of declaring an object from another project causes the error, but I don't see how that would prevent the server from starting.
Any ideas what I could be missing?

Related

How to run servlet Java on Tomcat server via Eclipse?

I created a test application with two files for educational purposes: mypage.jsp and mypage2.jsp. At the same time, the comLogin servlet class was created. The bottom line is that on a local server, a user visits the site, enters his name (say, Andrey) and receives a page with a greeting: Hello Andrew.
The server is starting. However, when I try to open a website with two pages via Run As, I get a system freeze and an error:
Loading descriptor for MyWeb has encountered a problem. An internal error occurred during "Loading descriptor for MyWeb"
The screenshot shows that the server is running. The screen also demonstrates the web download descriptor web.xml: it is in the project structure, although for some reason with a red cross (see the Project Explorer window on the left). What's the trouble then?

Java web app not responding to HTTP requests when deployed to Azure App Service using Windows app service plan

I have built a web app which runs with simply java -jar app.jar. It looks at the environment variable PORT to decide which port to listen on. now I want to deploy it to Azure with a Windows app service plan, this is called This is called "Java SE deployment" in Azure.
On a Linux app service plan, I can simply deploy the app.jar file (using vs code plugin, zipdeploy, or whatever), set the environment variable PORT, and everything is fine.
With a Windows app service plan, attempting to access the app gives a 500 error with the body "The web server failed to respond within the specified time". I've turned on all the logging I can, and I can see the request gets into IIS but no indication that it's attempted to send the request to my app.
However I can access my app directly from the Azure console using curl http://localhost:<port>. so I know it has started up.
I've done this tutorial https://learn.microsoft.com/en-us/azure/app-service/quickstart-java?tabs=javase&pivots=platform-windows which works fine, but I'm not using maven or spring boot - I need to build the jar file myself.
I've read https://learn.microsoft.com/en-us/azure/app-service/deploy-zip and https://learn.microsoft.com/en-us/azure/app-service/configure-language-java?pivots=platform-windows but they doesn't seem to be telling me anything I don't already know.
By dumping out the environment in my app, I discovered that Azure sets the environment variable SERVER_PORT to a number and that if you listen on that number, the requests are forwarded correctly. It actually sets quite a few environment variables to the same port number, but I chose SERVER_PORT because it looks like the most meaningful name, and there are some references to it in various blogs etc. HTTP_PLATFORM_PORT is also set.
I'd still be grateful for any references to official Microsoft documentation, so at least I know whether there's a "proper" way to do this.

Web application running without a name

I just made a simple web application (using java and jersey as i want to start making a rest endpoint). I am working on intelliJ idea
I used this tutorial to build it.
I gave the project a name, group id and artifact.
Now when i run it in my local tomcat server, it runs successfully but does not show me the name of my web application in URL. It only shows localhost:8080 as can be seen in the screen shot below.
Why is it displayed like that? How can i give my application a name/URL?
Basically, you need to watch this video first: Domains and the Domain Name System and then fully understand what the following paragraph means. Then your question will solve itself. Good luck! :D
localhost is the IP address of the server where the tomcat (which is an application server) is running. 8080 is the port. The localhost maps (from Windows hosts file) to 127.0.0.1 and this is a loopback IP address (meaning that it is, in fact, yourself).
p.s. that's what about the name in the URL. About the actual browser tab name, it's the <title> HTML tag.
How can i give my application a name/URL?
You need to buy a domain name.
So what i was looking for was to set the application context in tomcat server.
Here is how i did it: On IntelliJ idea, clicked on 'Edit configuration' -> than on 'Deployment' tab.
There is an option for "application context' there. I give it the name of my application(or any name that i like) and click 'apply' and restarted the server.
Here is how it appears in the browser now:

Cannot run java application on plesk

I uploaded java web aplication war file on plesk. Another application runs without problems on this host. but for this App, I got this error:
Actual status of the application does not correspond to the status retrieved from the database.
I read at this link, the error can be for the following reasons:
Tomcat service must be running on this server.
Tomcat service should be enabled on the domain.
Domain should be properly resolved in DNS to correct IP address.
Application should be packed into a valid .war package.
Does anyone have a solution to fix this error?

What happens to grails project on start if database is not running?

I have a grails project with mysql for GORM support. When i start project without mysql running, it gives me series of exception message. This is fine and expected. But, what is problem is that there is no way to handle that so that i can catch them and report to user that there is issue with system and they need to wait till it gets fixed.
There are two cases for this problem.
First one is when a currently running project (deployed inside tomcat and running) get its mysql connection killed by say stopping mysql service. In this case, it keeps on throwing database exception without any grace. The error catching mechanism fails for me. I have mapped 500 to a error page but it also does not gets rendered. Nginx which acts as reverse proxy at last displays its own timeout page.
Second case is when project start loading (say tomcat container is started) and mysql service is already down. In this case, the project startup seems to be effected to a level that startup fails though tomcat reports in log that war is running but when accessed it just throws black page (saying 404) which still is mysterious because i have mapped 404 to a error page which is also not in work.
Thanks.
If there is no db at start up the war will not be loaded into tomcat at all. So you will get default 404 error pages at that point. There are errors thrown to the log in this case but not much else. So your users are hosting their own instances of their app it sounds like, what I like to do is expose a health page.
The health page can be at a known URL and in the case of no db you will get a 404 but you can document that any non 200 status code is an error and provide info on how to fix. Also if you are automating deployment this check is great for reporting status of the deployment.

Categories