1

I'm new in Java EE and Tomcat.

I worked on a REST Java application in OpenShift with JBoss EWS 2.0 and I had no problem. Recently, we got a server that I have to run my web service on.

Following How to deploy a war file in Tomcat 7, I went to my application root and used this command:

jar -cvf myapp.war *

Note that myapp is my application name for example.

I put the .war file to /base/path/of/tomcat/webapps/ and went to Tomcat GUI App Manager.

I saw that Tomcat created a folder with my .war name and put files into it, so I started my app but when I went to http://localhost:8080/myapp/ it returned 404. However, in OpenShift, when I opened it (opened root path), it displayed the index.html insomuch my webservice path is not valid and does not work.

please guide me and thank you for your time spent on my question.

Community
  • 1
  • 1
Seyed Ali Roshan
  • 1,476
  • 1
  • 18
  • 37
  • As per usual: Any errors in the server logs? Is there anything of interest in the server logs? – Gimby Aug 08 '16 at 09:50
  • no, everything seams work well. for example if I put text.html in myapp folder and open http://localhost:8080/myapp/text.html it opens but my app parts in seprate folder and i don't know how to access it – Seyed Ali Roshan Aug 08 '16 at 10:25
  • Well... then I can only guess it is something as silly as there either not being any index.html in the actual deployed war, the webapp name somehow being overridden to be something other than "myapp", or something similar simple thing to overlook. The logging should indicate which application are deployed and under which context name, is it 'myapp' ? – Gimby Aug 08 '16 at 10:28

3 Answers3

0

I have to write an answer because I can't comment.

I suggest to give us a copy of the web.xml file.

On another hand, you have to know that Tomcat is a Servlet Container and JBoss a full stack JEE server. If you have EJB in your web-app it will not works.

Clément Duveau
  • 399
  • 3
  • 14
0

AS Clément Duveau says an EJB application cannot be deployed in a Servlet container (like Tomcat). An EJB application needs to be deployed in an Application Server like JBoss, Wildfly, GlassFish, Weblogic, Websphere, TomEE, etc.

The most similar server to Tomcat (Java EE compliant) would be TomEE.

Suggestion: If you need to use Tomcat, you can change EJB for Spring Framework.

fiso
  • 1,375
  • 1
  • 14
  • 20
  • it runs on localhost with tomcat 7.0 and 8.0 but netbeans deploys it. so this means it is possible to deploy it on normal tomcat but i don't know how to do this – Seyed Ali Roshan Aug 17 '16 at 23:04
  • @SeyedAliRoshan Do you mean that your application works in a local Tomcat when it is deployed by Netbeans? So, you problem is that you don't know how to do a manual deployment? – fiso Aug 18 '16 at 09:35
0

it is simple.

there is two way to deploy a war file on tomcat with custom path

the first one is to renaming your war file to custom URL you want (for example the war file name is java-web-app-1.0.war and your path is myapp so you have to rename it to myapp.war)

and copy and put it under {tomcat-path}/webapps/, then the Tomcat/TomEE does its job. (it creates an empty directory with the same name of your war file)

after about 1 minutes you can check the path (in this example must be localhost:8080/myapp and see your war file was deployed)

the second one is to use Tomcat GUI.

go to Web Application Manager part.

it's a page like this:

enter image description here

in Deploy box just fill the Context field (it will be the custom path and in this case is myapp) and then choose the war file and push deploy button.(do not need to fill XML Configuration file URL field)

then it gives you a message like this:

enter image description here

this means your war file was deployed on the custom path.

Seyed Ali Roshan
  • 1,476
  • 1
  • 18
  • 37