Remote Tomcat .war deployment base URL change - java

I was developing an application using my localhost apache-tomcat webserver. And when I was deploying my application using intellij idea, I had no problems with URL's, to reach an app I used URL:
localhost:8080
But now I tried to deploy my application on remote server installed on Ubuntu 10.04.4 LTS, and I got a problem with base URL change. I created a .war artifact and copied it with additional libraries to webapps folder of remote tomcat. The name of my project is Spider. After starting tomcat on remote server, I can only reach my application using URL:
serverIpAddress:8080/Spider
But because I have a /Spider in my base URL all my links on the pages does not lead to appropriate controllers, and I have 404 error. For example working link is: serverIpAddress:8080/googleApi, but link leads to serverIpAddress:8080/Spider/googleApi.
How can I solve this problem? Thank you in advance, and sorry for my poor English.

Your problem is that you are using absolute links, which is very bad practice. If you will have some proxy or load balancer before your app it will not work also. So the solution is to use only relative paths in all view pages. Another thing which is not good is using case sensitive characters, I would personally use only small ones especially on Linux platform. If you really want your app available as root you can deploy it by overriding ROOT directory in tomcat weapp, but please be aware that it will destroy tomcat standard Management GUI

Related

How to get started on Google App Engine for current GlassFish solution

I'm currently running my Java application on a GlassFish server on AWS-EB.
Since our front-end is already running on the Google Cloud Platform, I would like to migrate my back-end to GCP as well.
I tried the Jelastic interface but I was not happy with the speed results.
Now I'm looking to deploy my application on the App Engine but when I deploy my current .war file, I get the following error:
Error 404 - Not Found.
No context on this server matched or handled this request.
Contexts known to this server are:
/ ---> o.e.j.w.WebAppContext#7e0b0338{/,file:///var/lib/jetty/webapps/root/,UNAVAILABLE}{/root.war} [failed]
I guess I'm missing something, since GCP is using Jetty as a server.
I'm a bit lost and I hope you guys can point me in the right direction to make this migration successful.
It's suggested here that Jetty requires two configuration files (web.xml and applicationContext.xml).
As well as this, the original poster in the issue above stated that they solved their issue in this GitHub post by rebuilding their project before deploying.

Apache and Tomcat Server Cross Domain

I have three distinct heavily coded web-projects; two of them (new) is newly developed with Java/Script, the other (old) one with PHP. All of these three project has some common resources like HTML containers, Element classes etc. Moreover, one of the Java project is Main Project that call the other two projects.
The issue is that Java projects run on a Tomcat Server, PHP needs to run on Apache Server. And PHP project has some location paths for resources like "../SomeResourceFolder/somePage.php". However, when I run Main Project (Java) on Tomcat Server which has "localhost:8080" I could not reach PHP project which is run on Apache Server with "localhost:80", even if I accomplish to reach PHP project, PHP one fails to reach common resources in Tomcat.
I solve the issue a little bit unconvincing way with JavaBridge and Quercus; they help to run PHP on Tomcat Server. However, again I have some path problems.
Actually these projects runs on production with load-balancer which direct request to related server. I try to simulate this or at least run PHP on Apache, Java on Tomcat and connect them somehow. How can I construct this kind of structure without cross domain problems?
I solve the issue by using "Tomcat Connector". It connect Apache and Tomcat by defining Tomcat as worker, and send HTTP request with given path configuration.
You can follow guide given by Nanyang University. In guide Tomcat 6 and Apache 2.2 are used but I used Tomcat 7 and Apache 2.4 with the same directions.

How to deploy a JSP on to a server other than Tomcat

I am trying to deploy a JSP/servlet onto a server. Not tomcat but on a real web domain. This is my first time doing so and so far I exported it into a war file and placed the file onto the server. Nothing happened which is why I am here. All the google searches seem to concentrate on Tomcat which I have already ran the project on. Advice?
Ok, let's get really basic. You want to see the compiled JSP in a browser, through some public URL, right?
First, find a place to host your application. You can try Digital Ocean (starts at $5/mo), EATJ (free version available), Amazon AWS (free trial available), OpenShift (free gears available), your own computer with dynamic DNS, or many other options available through Google.
Next, you packed your compiled code to a war file. That war file needs to be unpacked (deployed) using some software.
There are numerous ways to handle this (Tomcat, Jetty, Glassfish, etc.). They all have their pros and cons. Pick one and learn the very basics. Tomcat doesn't require a separate web server but you can set one up with it if you like. At this stage, I would keep it simple and not do that yet.
Lastly, set up GoDaddy (or whomever you used to get your URL) to point to the IP address of that server. If your server is running and enough time has passed for the changes to propagate, you should see your page.
There are plenty other J2EE server for example, JBoss and Glassfish. Each one has it's own way to deploy your war files. For example, Glassfish is throught a web administration console (https://docs.oracle.com/cd/E19798-01/821-1757/6nmni99aj/index.html) and in JBoss you need to deploy the war file in a specific directory (http://docs.jboss.org/jbossweb/3.0.x/deployer-howto.html).
It depends on which J2EE server you are using.
Now if you want to get your own server and configure it:
Get the server or VPS
Install JAVA
Install Apache
Install a J2EE server (I prefer glassfish)
Configure glassfish with apache (http://www.codefactorycr.com/glassfish-behind-apache.html) to use apache in front of glassfish
You may want to block the ports 4848 and 8080 used by glassfish
Deploy your webapp
Have fun!!!
PS: I'm assuming you have root access to the server
Easy Apache Tomcat 7 install after,
Run Code via SSH:
/usr/local/cpanel/scripts/addservlets2 --domain=domain.com
For Linux.

Is there a way to run and execute Java files using HTTP from another PC?

I have installed Java and developed on my laptop. Now I want to access those files from my PC using HTTP. Both machines are on the same network. I'd like to access the page as we do in PHP:
http:// and the path
How can I do it? I can see the files using this url: file://machine-name/login.html, but it's not opening in HTTP, replacing file from the url. Please help
Unlike PHP, in Java you can serve only JSP or Servlets. You will need to have an Application Server - like Tomcat, to deploy your web components. There are many different ways how you can package your web components. Typically all files (JSP, Servlets, Classes) etc. are packaged in a 'war' file. Thiw war file can be deployed to any Java compliant application servers.
Try this URL - Simple Tomcat application
Hope this helps.
Regards,
Sreehari.

Tomcat setup issues

I'm trying to run a simple JAX-WS example I found on the web. So I wanted to setup Tomcat 7 under windows xp using Eclipse Helios 32 bit as the web server.
I remembered I had to have my app added as a resource to the Tomcat server, but nothing is coming up as a resource to add. I just have WS-Server and WS-Client projects for the app.
I've done this before, checked the server.xml and see http 1.1 port is 8080, but when I start up Tomcat under eclipse I'm getting a 404 error with this url: http://localhost:8080/, so Tomcat isn't really running properly.
What am I missing here?
Thanks!
If you're getting a 404 - that means the web server is running. This likely means you don't have anything mapped to the path specified (no servlets/default web page/etc).
Either make a servlet and add it to your web.xml or define a home page html file.
FYI, if you use the "Dynamic Web Project" setup; most of this is done for you. Here is a youtube video I always default to when I need to get a review on how to set up a quick tomcat instance in eclipse.

Categories