Trying to use tomcat with eclipse - java

I am trying to use tomcat with eclipse. I have installed it all and got the tomcat plugin installed. I have put a .war file in the webapps folder of tomcat and have made sure autodeploy is set to true. The problem I am having is that I can't get tomcat to run this .war file. The tomcat server is started and running as it tells me under the servers tab at the bottom of eclipse. It also shows the name of my .war file under it and says synchronized meaning it at least knows its there. But I can't get it to work at all. Even when I go to the local host page it shows the title of apache tomcat but does not show the file. I want it to show me the .war file. It has the correct xml files and everything in it. Any help is much appreciated.

You may try to check whether the application is deployed or not. You can directly go to the Tomcat directory to see this.
Another possible thing could be, you might be typing the incorrect url.
http://localhost:8080/[your_application]
where 8080 is the port you have specified for tomcat.

You need to let Eclipse publish your web project for you when using the Eclipse Tomcat plugin instead of trying to manually deploy it youself.
The Tomcat plugin for Eclipe supports hot deployment whereby you can change jsp's etc without having to manually redeploy your web application.
If you have a valid web project in eclipse then you can check that it is being deployed by looking at the Server View.
Window, Show View, Other, Server
This window should contain details of your Apache server. (If no server is listed then you'll need to right click on the list and set one up.)
To check that your application is being deployed right click on your server and select Add/Remove projects. Check that your web project is listed. If it is not listed under Configured Project then add it.
If your project does not appear in the list then it probably wasn't setup as a Dynamic Web Project. You can fix this by by right clicking on the project to bring up project properties and then clicking on facets and then enabling Dynamic Web Project.
It is also worth having the Console view visible when starting/stopping Tomcat so that you can see the server output.

Start tomcat from the command line (not eclipse) and see if your webapp shows up. It should if you have indeed created a valid war file. If it doesn't work, check the logs.
You shouldn't be manually deploying the war file if you are using eclipse to launch tomcat. Running tomcat from eclipse does not necessarily use the same default workspace as the standalone tomcat. Check the configurations for the 'server': it may be that the eclipse launched server's webapp folder is empty.

If for some reason your webapp failed to initialize properly (error in the descriptor, an uncaught exception in a context listener, ...) tomcat will unload it and you won't see anything at http://localhost:8080/yourwebapp.

Is it there in the list of applications in tomcat manager?
if you havent done this...then follow the steps...
Go to http://localhost:8080/
Go to Tomcat manager and check if your application is there in the list of deployed applications. Try redeploying or starting the application if running=false. It usually tells you what is wrong when you do that.

Related

Can't get a Java Spring webapp to deploy to Tomcat

I've got a project in Eclipse, with a .war file inside it. I'm using Spring for the project, with the help of Maven too.
I've installed Tomcat 8, but I'm having trouble deploying the webapp to Tomcat. The Tomcat runs without errors and the console output of launching the Tomcat looks like it is successfully deploying it, however when I go to localhost is just displays the generic Tomcat home page saying I have successfully deployed Tomcat.
I've tried changing my server location to use the tomcat installation, I've changed the location in the properties of my server to not be the workspace metadata.
When I add jars to the tomcat, I click on my project, and under it it lists the Spring jar if that is of any relevance.
I don't really know what else to put here at the moment, but I'm at hand to respond immediately to any questions or any more info that you require.
Thanks.
EDIT:
http://localhost:8080, it leads me to this: http://i.imgur.com/82lmpai.png
My tomcat console output is: https://gist.githubusercontent.com/J-Owens/8164b3ec6dbed9986322/raw/6756486aad0092647bbea8f315c42ac5ba9550b1/tomcatconsole
Each war file will have a name associated with it. When you use localhost:8080 as the URL, Tomcat will use the war with name ROOT under tomcat/webapps to display on the browser. By default, Tomcat will have a ROOT war that comes with the tomcat bundle. If you need to open your project, you will need to use localhost:8080/<your-war-name> to open your project's page. Alternatively, you could remove everything under tomcat/webapps and rename your war to ROOT to be able to access your project pages with the localhost:8080.

What is happening when I right click JBoss Runtime Server with a web project in Eclipse and choose "Clean"?

I usually do it when I add projects to Jboss or after changing datasource connection. But I don't know what is happening 'behind the scenes'.
It removes your deployed project from the web server. It has nothing to do with JBoss. Have you ever visited the directory where your application is deployed ?? If not, then I will recommend you to visit the directory where actually your web-app is deployed in JBosss. There you will see a folder named as your web-app something like this MyProjectEAR.ear if the project is an ear project with name MyProjectEar. Now I will ask you to click on "Clean". As soon as you do that, you will see that the folder vanishes, and later again appears when you again publish your app.
So to sum up, this action removes your deployed project and helps in re-publishing of your app. This helps in normal functioning if there is a major change in your app and the server fails to hot deploy it.

Do I have to restart tomcat everything for every jsp or java change?

I am running tomcat v7.0 within my eclipse. I have to restart tomcat for every single jsp or java change. I am sure I have set my server wrong somehow. How can I see my changes without keep restarting tomcat?
Thanks!
When you are deploying to the tomcat from eclipse, If you are planning to work without deploying every time you to a change to the code base, you can use Jrebel.
Jrebel will sense your changes and take care of the re-deploying. Only issue is that It is a have to buy plugin and I know there are opensource or free applications like that.
If you are running the application in DEBUG mode, it will auto restart every time you make any change to ur JSP or java code.
You can try deleting the tomcat instance from eclipse and also the Servers folder that is present in the Project Explorer. Add your server to eclipse again and deploy your war file. The changes to JSP or javascript files will now reflect without a server restart.
That not necessary it's depend upon your configuration
When you configure Tomcat in eclipse then we have 3 option
never publish automatically
automatically publish when resource change
automatically publish after build event
so you can configure this as per your requirement.You get this option once you create tomcat server in eclipse ,then select the tomcat server,then either press F3 or right click and open.
i prefer point 2 to select and make sure you have uncheck build automatically in eclipse ,so that once you sure about all the changes you can build the project and tomcat get restart automaticcaly

How to deploy the war file generated by maven on tomcat using eclipse?

I have got a war file generated using Maven and it works perfectly fine when i manually deploy it on the tomcat server.
However, the war file was generated using Maven on eclipse and when i try deploying this on the server using eclipse, it just doesn't act. The tomcat server starts perfectly fine. What I do is : Right click on the Tomcat Server 7.0, then Add/Remove Project and add it to the server.
The problem is when I deploy and publish it on the server and nothing happens after that.
On trying to access it, it says - The required resource is not found
Eclipse doesn't deploy the WAR. Instead, it knows how Tomcat works and deploys the exploded WAR.
The next step is to look into the webapps/ folder of Tomcat to make sure Eclipse really has deployed something.
If that looks ok, you need to look into the Tomcat log to see why it doesn't like the deployed web app.
Most of the time, there is old code which is somehow stuck in Tomcat, so Tomcat can't undeploy the old version. If that's the case, stop Tomcat, delete the app manually and try again.
There were certain jars required in specific versions for the application to work. I was usin the maven supported versions. I have got it to work adding them directly in Tomcat's lib folder for time being and the application now works. (Anyways i need to look to get them configured now on the maven)
Also, i guess installing the plugin for m2e - eclipse.org/m2e-wtp helped as well. Thanks #Aaron Digulla for the inputs.

Tomcat 6 is running in Eclipse but localhost:8080 never responds in browser

I integrated Tomcat 6 into Eclipse Indigo. When I start the server in Eclipse, it shows that Tomcat is up and running, but when I go to localhost:8080 in my browser, it does not respond at all.
I have Tomcat server entry in the Servers tab with "Use Tomcat Installation" and it didnt help me.
I have removed my entire projects from eclipse and started importing it again to set it up from the beginning and it didnt help either.
Could you please some help me out?
It is most probable that you are running Tomcat from eclipse as Use workspace metadata (does not modify Tomcat installation). While running under metadata, tomcat's default welcome page is not deployed. So you wont be able to view the welcome page under localhost:8080/ but you can access your application with the application context in the url ( something like localhost:8080/yourApplicationContext/hello.jsp)
See below the image where you can set the server location. If you change it to Use Tomcat Installation, eclipse will use the actual installation of tomcat. You can even see this by deploying the application and then open up your file browser, navigate to tomcat directory and you will see your application deployed there in the webapps folder. But if you use use workspace metadata option, eclipse makes a stripped copy of your tomcat's installation and places it in the .metadata folder of the workspace. Something like eclipse_workSpace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\
The question as to which technique is better totally depends on your use.

Categories